= JSON Jackson DataFormat
:doctitle: JSON Jackson
:shortname: jackson
:artifactid: camel-jackson
:description: Marshal POJOs to JSON and back using Jackson.
:since: 2.0
:supportlevel: Stable
:tabs-sync-option:
//Manually maintained attributes
:camel-spring-boot-name: jackson

*Since Camel {since}*

Jackson is a Data Format that uses the
https://github.com/FasterXML/jackson-core[Jackson Library]

[source,java]
-------------------------------
from("activemq:My.Queue").
  marshal().json(JsonLibrary.Jackson).
  to("mqseries:Another.Queue");
-------------------------------

== Jackson Options



// dataformat options: START
include::partial$dataformat-options.adoc[]
// dataformat options: END

== Usage

=== 4-byte characters

Jackson by default outputs 4-byte characters (in languages such as Japanese) as surrogate pairs, escaped. This is
compliant with Json specification. This can however frustrate users, because it garbles regular output, such as
names and texts with Unicode escapes. To avoid this, users commonly using 4-byte characters would need to set
`combineUnicodeSurrogates=true` in the Camel dataformat.

=== Using custom ObjectMapper

You can configure `JacksonDataFormat` to use a custom `ObjectMapper` in case you need more control of the mapping configuration.

If you set up a single `ObjectMapper` in the registry, then Camel will automatic lookup and use this `ObjectMapper`.
For example, if you use Spring Boot, then Spring Boot can provide a default `ObjectMapper` for you if you have Spring MVC enabled.
And this would allow Camel to detect that there is one bean of `ObjectMapper` class type in the Spring Boot bean registry
and then use it. When this happens you should set a `INFO` logging from Camel.

=== Using Jackson for automatic type conversion

The `camel-jackson` module allows integrating Jackson as a xref:manual::type-converter.adoc[Type Converter].

This gives a set of out-of-the-box converters to/from the Jackson type `JSonNode`, such as converting
from `JSonNode` to `String` or vice versa.

==== Enabling more type converters and support for POJOs

To enable POJO conversion support for `camel-jackson` then this must be enabled,
which is done by setting the following options on the `CamelContext` global options, as shown:

[source,java]
----
// Enable Jackson JSON type converter for more types.
camelContext.getGlobalOptions().put("CamelJacksonEnableTypeConverter", "true");
// Allow Jackson JSON to convert to pojo types also
// (by default, Jackson only converts to String and other simple types)
getContext().getGlobalOptions().put("CamelJacksonTypeConverterToPojo", "true");
----

The `camel-jackson` type converter integrates with xref:dataformats:jaxb-dataformat.adoc[JAXB]
which means you can annotate POJO class with `JAXB` annotations that Jackson can use.
You can also use Jackson's own annotations in your POJO classes.

== Dependencies

To use Jackson in your Camel routes, you need to add the dependency
on *camel-jackson*, which implements this data format.

If you use Maven, you could add the following to your `pom.xml`,
substituting the version number for the latest & greatest release:

[source,xml]
----------------------------------------------------------
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jackson</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----------------------------------------------------------


include::spring-boot:partial$starter.adoc[]
