0

Hi following is my cxfrs server configuration

<cxf:rsServer id="itemService"
        address="{{esb.item.rest.address}}"
        serviceClass="com.test.esb.service.flm.ItemServiceImpl"
        loggingFeatureEnabled="false">
        <cxf:providers>
            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
        </cxf:providers>
    </cxf:rsServer>

I need to configure Inclusion.NON_NULL here so that it can exclude the null fields from the generated gson string. Any idea how i can achieve this.

Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
vashishth
  • 2,751
  • 4
  • 38
  • 68

1 Answers1

2

One option is to create a customized provider instance using your own factory method. Here is an example factory class:

public class JacksonJsonProviderFactory {

    public static JacksonJsonProvider create() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return new JacksonJsonProvider(mapper);        
    }
}

And here is an example XML Blueprint fragment:

 <cxf:providers>
       <bean class="JacksonJsonProviderFactory" factory-method="create"/>
 </cxf:providers>
Alexey Gavrilov
  • 10,593
  • 2
  • 38
  • 48