Gabriele Del Prete opened SPR-8324 and commented
Currently, the Formatter subsystem in Spring guarantees that Parsers and Printers never have to handle null values. I believe this should be changed to allow for null values in the "object" side of the conversion. That means modifying the system so that Parsers can return null as the parsed object, and Printers can accept null as the object to be formatted.
This would allow to use null as a valid value, which might be required when interfacing with/building on legacy systems.
Right now, Parsers cannot return null or you'll immediately get a NullPointerException (on the conversion to targetType; see ParserConverter class in FormattingConversionService), while Printers will never be called if the object being formatted is null (see PrinterConverter class in FormattingConversionService).
I believe this specification change to Parser is fully backward compatible. The one to Printer is not (as Printers right now are never called on null), so maybe we could introduce a tag interface "NullAwarePrinter" that printers have to implement if they want to be passed null values (if they don't, just fall back to the current behavior).
Note: this is similar to issue #12969; however, #12969 involves only Parsers and the empty string value, and this one really is just an improvement, while the other is a bug (IMHO).
Affects: 3.0.5
Reference URL: http://forum.springsource.org/showthread.php?101583-Why-does-the-Formatter-system-ignore-null-values
Issue Links: - #12969 Formatter subsystem's ParserConverter skips Parser invocation if input string is empty
Comment From: spring-projects-issues
Juergen Hoeller commented
Closing groups of outdated issues. Please reopen if still relevant.