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>


The jaxb annotation and providers needed to get built from github:

https://github.com/FasterXML/jackson-module-jaxb-annotations.git

https://github.com/FasterXML/jackson-jaxrs-providers.git



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?
>>
>
>

Reply via email to