Camel JSON Marshalling

@drse / updated July 02, 2015

Share:  

Default:

// xstream default
from("direct:input")
.marshal()
.json()
.to("log:main?showBody=true")

However, this will not automatically serialize the string, but can break it up into component objects, giving results like:

{"map":{"entry":[{"string":"input3","list":{"string":[1,2]}},{"string":["input2","abc123"]},{"string":["input1","abcde"]}]}}

If so, use Jackson:

import org.apache.camel.model.dataformat.JsonLibrary

// ...

from("direct:input")
.marshal()
.json(JsonLibrary.Jackson)
.to("log:main?showBody=true")