...
Code Block |
|
<from uri="direct:inPojoAgeView"/>
<marshal>
<json library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView" jsonView="org.apache.camel.component.jackson.Views$Age"/>
</marshal>
|
Setting serialization include option for Jackson marshal
Available as of Camel 2.13.3/2.14
If you want to marshal a pojo to JSON, and the pojo has some fields with null values. And you want to skip these null values, then you need to set either an annotation on the pojo,
Code Block |
@JsonInclude(Include.NON_NULL)
public class MyPojo {
...
}
|
But this requires you to include that annotation in your pojo source code. You can also configure the Camel JsonDataFormat to set the include option, as shown below:
Code Block |
JacksonDataFormat format = new JacksonDataFormat();
format.setInclude("NON_NULL");
|
Or from XML DSL you configure this as
Code Block |
<dataFormats>
<json id="json" library="Jackson" include="NOT_NULL"/>
</dataFormats>
|
Dependencies for XStream
To use JSON in your camel routes you need to add the a dependency on camel-xstream which implements this data format.
...