On Tue, Aug 7, 2012 at 2:54 PM, James Green <james.mk.green_at_gmail.com> wrote:
> Tatu,
>
> See inline responses.
>
> On 7 August 2012 17:11, Tatu Saloranta <tsaloranta_at_gmail.com> wrote:
>>
>>
>> The way I have registered plain data-binding JSON object mapper for
>> Jersey and RESTeasy has been by using JAX-RS
>> `javax.ws.rs.core.Application`, which allows specifying objects that
>> provide (aka Providers) handlers of various kinds. For JSON support,
>> this means `MessageBodyReader` (read JSON to produce Java objects) and
>> `MessageBodyWriter` (write Java objects as JSON). Jackson project has
>> module [https://github.com/FasterXML/jackson-jaxrs-json-provider] that
>> implements both.
>
> [ ... ]
>>
>> With that, what needs to be done is:
>>
>> (a) construct `com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider`
>> (if using Jackson 2.0; 1.x version is under package
>> `org.codehaus.jackson.jaxrs`)
>> (b) return instance of that provider from Application.getSingletons()
>> method
>>
>> and with Jackson 2.0, in fact, even less is needed: you _should_ just
>> be able to add the provider jar in classpath, and it should be
>> auto-detected (1.x jar did not do this, since we were not sure if it
>> should override default mappings).
>
>
>
> OK, I've hooked up a real simple project with a Customer bean having
> @XmlRootElement. It works out the of box with an Application activator
> returning a JacksonJaxbJsonProvider.
>
> I've switched on SerializationFeature.WRAP_ROOT_VALUE to mirror our XML api
> documentation a little closer. Two things are otherwise immediately
> apparent:
>
> 1. The JSON has an empty root name:
>
> {
> "": {
> "id": 2
> }
> }
>
> Unless I expressly set the name of the @XmlRootElement. Can't find reference
> to this on Google though. Any ideas?
This does seem odd: the default behavior, if annotation is not used
(that, or Jackson's @JsonRootName), would be to use simple class name
of the value class.
> 2. I have switched off SerializationFeature.WRITE_DATES_AS_TIMESTAMPS again
> to mirror our XML API docs closer. My reading of the JavaDocs suggests that
> although not thread-safe by itself, the formatter is here only used by
> thread-safe framework methods. Is this correct?
It depends on how you do it -- if it is when initializing
ObjectMapper, or via ObjectWriter, it is safe.
Actually, with jackson 2.0, there should not be any unsafe way.
> I've run out of time to investigate tonight. I'll continue with my tiny app
> to try and get a representation does not differ from XML unnecessarily and
> post an update.
Ok, I hope it works out; and I will try to help as much as possible,
may well help many others who do the same.
>
> Thank you once more for your time.
No problem -- glad that we are making progress here,
-+ Tatu +-