JSON
Inbuilt JSON marshalling component: Transforms to and from JSON using the ultra-fast Jackson library
For more information about json-jackson: https://camel.apache.org/components/latest/dataformats/json-jackson-dataformat.html.
Example¶
Transforms the message body to a JSON string:
import org.apache.camel.model.dataformat.JsonLibrary
p6.camel.getCtx().addRoutes(new RouteBuilder() {
void configure() {
from("timer://jsonExample?repeatCount=1")
.setBody(constant([message: "hello"]))
.marshal().json(JsonLibrary.Jackson)
.setHeader("Content-Type", constant("application/json; charset=utf-8"))
.to("p6cmb://scripts?platform6.request.action=execute&id=p6_demo.JsonEventHandler")
.routeId("p6_demo Jackson - JsonEventHandler")
.description("p6_demo JSON Event Handler")
}
})
Warning
If you want to read the result of this JSON marshalling component transformation using the pipeline (in a script for example) you need to set the contentType header with a charset (as shown before). By default, the result of the transformation does not contain the charset.