Jackson JSON Processor
  1. Jackson JSON Processor
  2. JACKSON-309

Serialization of Null Properties in Jackson 1.5.3

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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 :
      0

      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);

        Activity

        Hide
        Francisco Lozano added a comment -

        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).

        Show
        Francisco Lozano added a comment - 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).
        Hide
        Francisco Lozano added a comment -

        1.5.4 still fails.

        Fixed by downgrading to 1.4.5.

        Show
        Francisco Lozano added a comment - 1.5.4 still fails. Fixed by downgrading to 1.4.5.
        Hide
        Tatu Saloranta added a comment -

        Thank you for verifying – it's not surprising, as no fixes for this issue were added.
        I need to add a unit test to verify, hope to fix it in time for 1.6 (and backport to 1.5 too of course)

        Show
        Tatu Saloranta added a comment - Thank you for verifying – it's not surprising, as no fixes for this issue were added. I need to add a unit test to verify, hope to fix it in time for 1.6 (and backport to 1.5 too of course)
        Hide
        Tatu Saloranta added a comment -

        Added unit test to reproduce, and yes, with Jackson annotation introspector, works as expected; but with JAXB one, does not.

        Show
        Tatu Saloranta added a comment - Added unit test to reproduce, and yes, with Jackson annotation introspector, works as expected; but with JAXB one, does not.
        Hide
        Tatu Saloranta added a comment -

        Haha. I should have checked the most obvious reason first – this was a very simple bug, JAXBAnnotationIntrospector returning 'null' instead of default value it is passed... At any rate, fixed for 1.5.5, trunk (1.6)

        Show
        Tatu Saloranta added a comment - Haha. I should have checked the most obvious reason first – this was a very simple bug, JAXBAnnotationIntrospector returning 'null' instead of default value it is passed... At any rate, fixed for 1.5.5, trunk (1.6)
        Hide
        Troy Waldrep added a comment -

        Great to hear that I'm not the only one who has run into this problem AND that it's fixed!

        Show
        Troy Waldrep added a comment - Great to hear that I'm not the only one who has run into this problem AND that it's fixed!
        Hide
        Francisco Lozano added a comment -

        Wow, that was fast! great! thankyou.

        Show
        Francisco Lozano added a comment - Wow, that was fast! great! thankyou.

          People

          • Assignee:
            Tatu Saloranta
            Reporter:
            Troy Waldrep
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: