Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.5.3
-
Fix Version/s: 1.5.5
-
Component/s: ObjectMapper
-
Labels:None
-
Environment:windows 7, java 6_20, FUSE ESB 4.2, jackson 1.5.3,
-
Number of attachments :
Description
We have discovered an issue related to serialization of null values to json in Jackson 1.5.3 (maybe earlier versions as well). Basically, we cannot get Jackson to stop serializing null values to JSON output when using the ObjectMapper. We did not see this issue in 1.3.0. I've tried the following methods:
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
and
mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false);
I'm now getting output like the following:
{ "name" : "My Server", "status" : "ONLINE", "logLevel" : null, "httpPort" : 8080, "httpProtocol" : "HTTPS", "licenseLocation" : null, "baseWorkDir" : null, "baseDataDir" : null, "maxLogSize" : 0, "shutdownDelay" : 60, "maxEngineCount" : 0, "minEngineCount" : 0 }The null properties in this JSON aren't there using the same mapper configuration in 1.3.0.
After some discussion in the mailing list, it's suspected that our paired use of the JAXB annotation introspector along with the default Jackson annotation introspector may be the culprit.
Following is our exact ObjectMapper configuration.
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.INDENT_OUTPUT, true);
mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false);
AnnotationIntrospector primary = new JacksonAnnotationIntrospector();
AnnotationIntrospector secondary = new JaxbAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospector
.Pair(primary, secondary);
mapper.getDeserializationConfig().setAnnotationIntrospector(pair);
mapper.getSerializationConfig().setAnnotationIntrospector(pair);
Same issue here, but I'm configuring my ObjectMapper with a single annotation instrospector:
mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
// make deserializer use JAXB annotations (only)
mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
// make serializer use JAXB annotations (only)
mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
// mapper.configure(Feature.WRITE_NULL_PROPERTIES, false);
mapper.configure(Feature.INDENT_OUTPUT, true);
mapper.configure(Feature.USE_STATIC_TYPING, true);
mapper.configure(Feature.WRITE_NULL_PROPERTIES, false);
mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
Using Jackson 1.5.3 also. Windows 7, Sun JDK 1.6.0_19 (x86).