THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- The XStream library and Jettsion
- The Jackson library
- Camel 2.10: The GSon library
...
As of Camel 2.10
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON 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-jackson/src/test/java/org/apache/camel/component/jackson/Views.java} |
@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-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java} |
JacksonDataFormat
to marshall the above POJO to JSON.Wiki Markup |
---|
{snippet:id=format|lang=java|url=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalViewTest.java} |
...
The GSON library supports a similar feature through the notion of ExclusionStrategies:
Wiki Markup |
---|
{snippet:id=strategy|lang=java|url=camel/trunk/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java} |
GsonDataFormat
accepts an ExclusionStrategy
in its constructor:Wiki Markup |
---|
{snippet:id=format|lang=java|url=camel/trunk/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java} |
@ExcludeAge
when marshalling to JSON....