users@jersey.java.net

RE: Jersey JSON unmarshalling of array elements.

From: <EWILLIAMS_at_CERNER.COM>
Date: Wed, 27 Jan 2010 09:55:32 -0600

I haven't received any response from you on the initial email, but I have done more investigation. It looks like the issue has nothing to do with arrays and is more about nested complex types.
I'm able to reproduce my JSON unmarshalling (@POST) problem with the following simple schema which JAXB generates objects for.
        <element name="carsHolder">
                <complexType>
                <sequence>
                        <element name="dog" type="tns:Dog"/>
                </sequence>
                </complexType>
        </element>
Where Dog is defined as:
        <complexType name="Dog">
                 <sequence>
                        <element name="id" type="long" minOccurs="1"/>
                </sequence>
        </complexType>

Here is the data passed in, which is exactly what is returned from a corresponding @GET of the carsHolder:
{
        "dog" : {
                "id" : 1234
        }
}


I can see the unmarshalling get to the element called "id". This is where things seem to go unexpected in the "StructureLoader" class.

    @Override
    public void childElement(UnmarshallingContext.State state, TagName arg) throws SAXException {
        ChildLoader child = childUnmarshallers.get(arg.uri,arg.local);
        if(child==null) {
            child = catchAll;
            if(child==null) {
                super.childElement(state,arg);
                return;
            }
        }

        state.loader = child.loader;
        state.receiver = child.receiver;
    }

arg.uri = "" and arg.local = "id", and child returns null from childUnmarshallers.get(arg.uri, arg.local);
Ultimately, it is passed up to the super and an unexpected child element is reported - whereby the whole thing appears to be ignored (no "id" object created, and predictor.expectText returns false for the value).
In the end, I end up with a "CarsHolder object" which has a "Dog object" inside of it, with the property "id" equal to 0 (rather than the expected 1234). I can get no property at this level to get unmarshalled properly (only tried simple types).

Can you tell me where to go with this issue, please?!
Thank you,
Ed


_____________________________________________
From: Williams,Ed
Sent: Friday, January 22, 2010 10:21 AM
To: 'users_at_jersey.dev.java.net'
Subject: Jersey JSON unmarshalling of array elements.


Hopefully, you can point me to the right people if you do not handle JSON questions.

I'm fairly new to Jersey, and have been producing/consuming xml for the most part.
I am using: jersey-json 1.1.4.1, jersey-server 1.1.4.1 and jaxb-impl 2.1.12.
I am using all defaults (no JSON provider, mapped

The issue:
The JSON I produce from a very simple test @GET does not get correctly unmarshalled when I pass it in to my @POST.
Specifically, the root object is created

Here is the JSON:

{
    "holderId" : "6666",
    "tests" : [
        {
            "allergyId" : "1111",
            "type" : "firstOne"
        },
        {
            "allergyId" : "2222",
            "type" : "secondOne"
        }
    ]
}


So there is an outer (JAXB-generated) class called TestArrayHolder which is created, but no properties are populated!
The marshalling seems to work like a charm, but I can get anything to unmarshall...

One last note that could be related: I run on Geronimo, so I had to add the hidden classes to get the JSON marshalling to pick up my project's xml/binding jars.
<sys:hidden-classes>
      <filter>com.sun.xml</filter>
      <filter>javax.xml.bind</filter>
</sys:hidden-classes>

I'm not sure what else to try from here. Can you help?

Thank you,
Ed


----------------------------------------------------------------------
CONFIDENTIALITY NOTICE This message and any included attachments are from Cerner Corporation and are intended only for the addressee. The information contained in this message is confidential and may constitute inside or non-public information under international, federal, or state securities laws. Unauthorized forwarding, printing, copying, distribution, or use of such information is strictly prohibited and may be unlawful. If you are not the addressee, please promptly delete this message and notify the sender of the delivery error by e-mail or you may call Cerner's corporate offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024.