> -----Original Message-----
> From: Aaron Titus [mailto:[email protected]]
> Sent: Wednesday, November 06, 2013 9:11 AM
> To: [email protected]
> Subject: Re: Concise summary of steps to integrate Jackson 2.x into CXF with
> Spring and JAXB annotations?
>
> The custom provider can be as simple as this:
>
> package mypackage;
>
> import com.fasterxml.jackson.databind.DeserializationFeature;
> import com.fasterxml.jackson.databind.ObjectMapper;
> import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
> import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
>
> public class CustomJsonProvider extends JacksonJaxbJsonProvider {
>
> // this class exists so we can customize the object mapper
> // and therefore the way that the JSON is produced
> public CustomJsonProvider() {
> ObjectMapper mapper = new ObjectMapper();
> mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
> JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule();
> mapper.registerModule(jaxbModule);
> this._mapperConfig.setMapper(mapper);
> }
>
>
> And then in the configuration file, it looks like this:
>
>
> <jaxrs:server id="restServer" address="/rest">
> <jaxrs:serviceBeans>
> ...
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <bean id="jaxbProvider" class="mypackage.CustomJsonProvider"/>
> </jaxrs:providers>
> </jaxrs:server>
I thought I had this all working, but I realized the resulting JSON output
isn't quite right.
In my sample data, I have this annotated class:
-----------------
@XmlType(name = "configInfo")
@XmlRootElement(name = "configInfo")
public class ConfigInfo {
@XmlElement(name = "foo")
private String foo;
@XmlElementWrapper(name = "devices")
@XmlElement(name = "device")
private List<Device> devices;
public final List<Device> getDevices() {
if (devices == null)
devices = new ArrayList<Device>();
return devices;
}
}
-----------------
I created an instance with just a single Device in the list, and this rendered
as the following:
{"device":[{"name":"abc","type":"def"}]}
The "device" property should be "devices". How do I make that happen?
> On Wed, Nov 6, 2013 at 12:03 PM, Aaron Titus <[email protected]> wrote:
>
> > I just went through this myself, and found the same struggle. One of the
> > challenges is that with Jackson 2.0 is that the JAXB stuff is now in
> > separate github projects, and there weren't any jars available. I had to
> > clone the github projects and build. I don't use spring in my app directly
> > but I do use the spring beans in the CXF configuration file. It was
> > difficult to try and define the parameters I needed directly in there so I
> > opted to extend the jackson jaxb provider class and then refer to my
> > provider within the spring configuration file. As Sergey mentioned, you
> > also need to use CXF 2.7.6 or greater otherwise you run into another
> > problem.
> >
> >
> >
> >
> > On Wed, Nov 6, 2013 at 11:47 AM, KARR, DAVID <[email protected]> wrote:
> >
> >> I'm trying to investigate integrating Jackson 2.x into a Spring CXF
> >> JAX-RS prototype, using JAXB annotations to facilitate both XML and JSON
> >> rendering. I've browsed the Jackson documentation, but it seems
> scattered.
> >> I have an older CXF JAX-RS app using Jackson 1.x, but I'd like to see
> what
> >> the newer Jackson does. I've seen some examples on the web using the
> older
> >> Jackson, but not the new one. Is there a straightforward guide to this
> >> somewhere?
> >>
> >
> >