On 24/01/13 08:39, jbright wrote:
I see the primary issue (unmarshal json containing list) is fixed, perhaps
its good for very small designs ..

In case of an enterprise application 'arrayKey' is a (unwanted /
unnecessary) configuration, having lot of elements that will be of list
type.  So while designing we need to keep a constant eye on the beans.xml to
add the list elements.... the maintainability is difficult.

Also, see the difference in what we get from JacksonJsonProvider and the
JSONProvider of Jettison.

*JacksonJson*

     {
        "errors": null,
        "smeHeader":
        [
            {
                "smeHeaderDtls":
                {
                    "name": "Jackson Json",
                    "age": 25,
                    "location": "India",
                    "doB": "1985-04-28"
                }
            }
        ]
     }

*Jettison*

     {
        "SearchMeResponse":
        {
            "SmeHeader":
            [
                {
                    "SmeHeaderDtls":
                    {
                        "Name": "Jackson Json",
                        "Age": 25,
                        "Location": "India",
                        "DoB": "1985-04-28"
                    }
                }
            ]
        }
     }


However, I would try to use Jettison If at all I can get the 'null' objects
also listed in the JSON response like the one in JacksonJson..

Well, Jackson is known to produce more optimal JSONs by default, kudos to the team, to be honest I think the only way to do it right is to have the introspection mechanism in place to know what exactly is coming next, a start of the array or something else; this is not possible at Jettison level - all it gets is the stream writer events when writing.

That said - you can easily configure JSONProvider to drop certain elements (example, with 'dropRootElement' property and/or transform drop [1]), and in combination with the keys hints you can control the output pretty well in many cases. In this case setting "dropRootElement" will do.

Regarding 'null' values: I'm not sure yet - again depends on how JAXB Marshaller reports empty collections - may be it does not even report them, if it does not then we won't be able to do it, otherwise we may be able to configure it somehow. In cases like this extending JSONProvider and registering a basic writer will work well for simple cases, for example, one can get this writer check if "errors" has been reported by the time "smeHeader" is being reported, if not - preprocess it with start/stop "errors" event, with value being 'null' - I can provide more info if you'd want to experiment

Cheers, Sergey

[1] http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CustomizingJAXBXMLandJSONinputandoutput



Sergey, could you pls let me know on how to get the null objects also..



--
View this message in context: 
http://cxf.547215.n5.nabble.com/JSONProvider-unable-to-unmarshal-json-containing-list-of-elements-tp5715651p5722115.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to