Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When marshalling a POJO to JSON XML you might want to exclude certain fields from the JSON XML output. With Jackson you can use JSON views to accomplish this. First create one or more marker classes.

Wiki Markup
{snippet:id=marker|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java}
Use the marker classes with the @JsonView annotation to include/exclude certain fields. The annotation also works on getters.
Wiki Markup
{snippet:id=jsonview|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java}
Finally use the Camel JacksonXMLDataFormat to marshall the above POJO to XML.
Wiki Markup
{snippet:id=format|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java}
Note that the weight field is missing in the resulting JSONXML:

Code Block
{"<pojo age=":30," "weight=":70}"/>

Include/Exclude fields using the jsonView attribute with JacksonXMLDataFormat

...