CXF
  1. CXF
  2. CXF-2916

unmarshalling the JSON of a subclass fails when a field value is null

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.9
    • Fix Version/s: 2.4, 2.3.4
    • Component/s: JAX-RS
    • Labels:
      None
    • Environment:

      Windows XP, JDK 1.6.0_14

    • Estimated Complexity:
      Moderate

      Description

      Unmarshalling the JSON :

      {"@xsi.type" : "subClassTest", "id" : "10000000", "name" : null }

      should give an instance of SubClassTest.class and the value of the field name(which is a String) should be null, but with the current implementation the value of the field name is String "null" .

      This happens only in the case of unmarshalling JSON to a subclass.

      1. CXF-2916.patch
        3 kB
        Andrew Nelson
      2. CXF-2916-jettison.patch
        0.8 kB
        Andrew Nelson

        Activity

        Hide
        Sergey Beryozkin added a comment -

        Andrew, your patch has been applied to Jettison 1.3-SNAPSHOT trunk, thanks.

        Just FYI, JAXB, as opposed to Aegis, reports an empty string instead of null.

        I suspect this is because Jettison now reports START and END element events but does not report CHARACTERS if 'currentValue' is null so JAXB assumes it is the case of something like <id></id>, thus, when we have 'String id', it sets the value of it to "".

        I reckon that Jettison may need to enhanced a bit more to deal with properly, that is, if currentValue is null, then, rather than reporting START_ELEMENT, it has to completely skip the current node, but only if it is a simple element, possibly calling processElement() instead of setting an event to START_ELEMENT.

        However, I'm not too worried if that not get fixed right now, empty value is definitely better than "null" and as you can see Aegis defaults to "" in case of null.

        Please also check JSONProvider.testReadListOfDerivedTypesWithNullField

        Show
        Sergey Beryozkin added a comment - Andrew, your patch has been applied to Jettison 1.3-SNAPSHOT trunk, thanks. Just FYI, JAXB, as opposed to Aegis, reports an empty string instead of null. I suspect this is because Jettison now reports START and END element events but does not report CHARACTERS if 'currentValue' is null so JAXB assumes it is the case of something like <id></id>, thus, when we have 'String id', it sets the value of it to "". I reckon that Jettison may need to enhanced a bit more to deal with properly, that is, if currentValue is null, then, rather than reporting START_ELEMENT, it has to completely skip the current node, but only if it is a simple element, possibly calling processElement() instead of setting an event to START_ELEMENT. However, I'm not too worried if that not get fixed right now, empty value is definitely better than "null" and as you can see Aegis defaults to "" in case of null. Please also check JSONProvider.testReadListOfDerivedTypesWithNullField
        Hide
        Andrew Nelson added a comment - - edited

        As requested the patch + test cases has been attached to http://jira.codehaus.org/browse/JETTISON-89 .

        Show
        Andrew Nelson added a comment - - edited As requested the patch + test cases has been attached to http://jira.codehaus.org/browse/JETTISON-89 .
        Hide
        Sergey Beryozkin added a comment -

        Hi Andrew

        Can you please attach CXF-2916-jettison.patch to http://jira.codehaus.org/browse/JETTISON-89, if possible with a simple
        Jettison test ? This will make if feasible to start talking about say Jettison 1.2.1. We can't really depend on 1.3-SNAPSHOT, this would be a major release, with some major fixed/enhancements and it is unlikely to happen in the short term. 1.2.1 is more realistic.

        In meantime, the only thing you can do in CXF is to register a custom provider extending JSONProvider and override createReader(). Delegate to the superclass first and then wrap the returned reader in your own. Then somehow deal with "null" sequences...

        Show
        Sergey Beryozkin added a comment - Hi Andrew Can you please attach CXF-2916 -jettison.patch to http://jira.codehaus.org/browse/JETTISON-89 , if possible with a simple Jettison test ? This will make if feasible to start talking about say Jettison 1.2.1. We can't really depend on 1.3-SNAPSHOT, this would be a major release, with some major fixed/enhancements and it is unlikely to happen in the short term. 1.2.1 is more realistic. In meantime, the only thing you can do in CXF is to register a custom provider extending JSONProvider and override createReader(). Delegate to the superclass first and then wrap the returned reader in your own. Then somehow deal with "null" sequences...
        Hide
        Andrew Nelson added a comment - - edited

        This issue seems to be caused by http://jira.codehaus.org/browse/JETTISON-89 .

        The attached file (CXF-2916.patch) should be applied the cxf trunk.
        The attached file (CXF-2916-jettison.patch) should be applied to the jettison trunk.

        Show
        Andrew Nelson added a comment - - edited This issue seems to be caused by http://jira.codehaus.org/browse/JETTISON-89 . The attached file ( CXF-2916 .patch) should be applied the cxf trunk. The attached file ( CXF-2916 -jettison.patch) should be applied to the jettison trunk.

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Chaitanya Choleti
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 24h
              24h
              Remaining:
              Remaining Estimate - 24h
              24h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development