Jakub,
I tried out ObjectMapper context resolver and it works fine.
Unfortunately for me, my interpretation of Jackson's
SerializationConfig.Feature.WRAP_ROOT_VALUE seems to be faulty. When a
collection of XmlRootElement annotated POJOS are serialized, the name for
the top level JSON object seems to be the Java type of the Collection...for
e.g.
{
"ArrayList" : [ {
"name" : "John"
}, {
"name" : "Smith"
} ]
}
If no collection is used, and a single instance is being serialized, the
XmlRootElement's name attribute is honored. For e.g.
{
"myBean" : {
"name" : "John"
}
}
It makes sense I suppose, however I was looking for Jersey's Natural
annotation implementation style when it came to this aspect.
So I guess I will stick with the approach of implementing a custom
JAXBContextResolver and using
JSONConfiguration.natural().rootUnwrapping(false).build().
Thanks for your prompt help.
Any comments on the original question of why the Mapped notation parsing
hangs or on zzantozz's analysis?
- Naresh
Jakub Podlesak-2 wrote:
>
> Hi Naresh,
>
> in the user guide doc [1] there is a note on this (see the last para of
> the respective chapter).
> You can check out the Jackson JSON example [2] and see:
>
> @Provider
> public class MyObjectMapperProvider implements
> ContextResolver {
>
> @Override
> public ObjectMapper getContext(Class<?> type) {
>
> ObjectMapper result = new ObjectMapper();
> result.configure(Feature.INDENT_OUTPUT, true);
> return result;
> }
> }
>
> You should be able to set the other Jackson parameters there.
>
> HTH,
>
> ~Jakub
>
> [1]http://jersey.java.net/nonav/documentation/latest/json.html#d4e894
> [2]http://download.java.net/maven/2/com/sun/jersey/samples/jacksonjsonprovider/1.6/jacksonjsonprovider-1.6-project.zip
>
> On 03/29/2011 02:54 PM, nbaliga wrote:
>> Jakub,
>> I tried out what you mentioned w.r.t. the JSON POJO mapping feature.
>> Looks
>> like I will lose out on the
>> JsonConfiguration.natural().rootUnwrapping(false) capability. That is, I
>> want to see the @XmlRootElement's name value parameter in the output.
>>
>> Obviously this is a Jackson issue, if as you say, everything is delegated
>> to
>> Jackson in the JSON POJO mapping feature.
>>
>> After digging around a bit, I think I see that Jackson has an issue
>> resolved
>> for this in Jackson 1.7
>> http://jira.codehaus.org/browse/JACKSON-163
>> http://jira.codehaus.org/browse/JACKSON-163
>>
>> However in order to avail of this fix, i have to be able to access the
>> SerializationConfig i.e. the ObjectMapper instance that Jersey is using.
>>
>> Any idea whether how I can go about doing this? Any way to pass
>> configuration to Jackson via Jersey?
>>
>> Thanks,
>> Naresh
>>
>>
>>
>> --
>> View this message in context:
>> http://jersey.576304.n2.nabble.com/Jersey-hangs-when-invalid-JSON-is-sent-in-POST-request-tp6205397p6221112.html
>> Sent from the Jersey mailing list archive at Nabble.com.
>>
>
--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-hangs-when-invalid-JSON-is-sent-in-POST-request-tp6205397p6221852.html
Sent from the Jersey mailing list archive at Nabble.com.