This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new f4fcdc7075 Add more details to the Jackson ObjectMapper usage section f4fcdc7075 is described below commit f4fcdc70759c1f188656713f531d764f0d703bcc Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Tue Aug 2 18:01:57 2022 +0200 Add more details to the Jackson ObjectMapper usage section --- .../ROOT/pages/reference/extensions/jackson.adoc | 48 +++++++++++++++++----- extensions/jackson/runtime/src/main/doc/usage.adoc | 48 +++++++++++++++++----- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/jackson.adoc b/docs/modules/ROOT/pages/reference/extensions/jackson.adoc index c3a171043a..0c1a158adf 100644 --- a/docs/modules/ROOT/pages/reference/extensions/jackson.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/jackson.adoc @@ -56,9 +56,19 @@ You can pass a custom `ObjectMapper` instance to `JacksonDataFormat` as follows. [source,java] ---- -ObjectMapper mapper = new ObjectMapper(); -JacksonDataFormat dataFormat = new JacksonDataFormat(); -dataFormat.setObjectMapper(mapper); +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + +public class Routes extends RouteBuilder { + public void configure() { + ObjectMapper mapper = new ObjectMapper(); + JacksonDataFormat dataFormat = new JacksonDataFormat(); + dataFormat.setObjectMapper(mapper); + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) + } +} ---- ==== Using the Quarkus Jackson `ObjectMapper` with `JacksonDataFormat` @@ -67,18 +77,28 @@ The Quarkus Jackson extension exposes an `ObjectMapper` CDI bean which can be di [source,java] ---- -ObjectMapper mapper = new ObjectMapper(); -JacksonDataFormat dataFormat = new JacksonDataFormat(); -// Make JacksonDataFormat discover the Quarkus Jackson `ObjectMapper` from the Camel registry -dataFormat.setAutoDiscoverObjectMapper(true); +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + +public class Routes extends RouteBuilder { + public void configure() { + JacksonDataFormat dataFormat = new JacksonDataFormat(); + // Make JacksonDataFormat discover the Quarkus Jackson `ObjectMapper` from the Camel registry + dataFormat.setAutoDiscoverObjectMapper(true); + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) + } +} ---- If you are using the JSON binding mode in the Camel REST DSL and want to use the Quarkus Jackson `ObjectMapper`, it can be achieved as follows. [source,java] ---- +import org.apache.camel.builder.RouteBuilder; + @ApplicationScoped -public class Routes extends RouteBuilder() { +public class Routes extends RouteBuilder { public void configure() { restConfiguration().dataFormatProperty("autoDiscoverObjectMapper", "true"); // REST definition follows... @@ -90,6 +110,9 @@ You can perform customizations on the Quarkus `ObjectMapper` with a `ObjectMappe [source,java] ---- +import com.fasterxml.jackson.databind.ObjectMapper; +import io.quarkus.jackson.ObjectMapperCustomizer; + @Singleton public class RegisterCustomModuleCustomizer implements ObjectMapperCustomizer { public void customize(ObjectMapper mapper) { @@ -102,15 +125,20 @@ It's also possible to `@Inject` the Quarkus `ObjectMapper` and pass it to the `J [source,java] ---- +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + @ApplicationScoped -public class Routes extends RouteBuilder() { +public class Routes extends RouteBuilder { @Inject ObjectMapper mapper; public void configure() { JacksonDataFormat dataFormat = new JacksonDataFormat(); dataFormat.setObjectMapper(mapper); - // Routes definition follows... + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) } } ---- diff --git a/extensions/jackson/runtime/src/main/doc/usage.adoc b/extensions/jackson/runtime/src/main/doc/usage.adoc index 58b8061415..a2228710af 100644 --- a/extensions/jackson/runtime/src/main/doc/usage.adoc +++ b/extensions/jackson/runtime/src/main/doc/usage.adoc @@ -13,9 +13,19 @@ You can pass a custom `ObjectMapper` instance to `JacksonDataFormat` as follows. [source,java] ---- -ObjectMapper mapper = new ObjectMapper(); -JacksonDataFormat dataFormat = new JacksonDataFormat(); -dataFormat.setObjectMapper(mapper); +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + +public class Routes extends RouteBuilder { + public void configure() { + ObjectMapper mapper = new ObjectMapper(); + JacksonDataFormat dataFormat = new JacksonDataFormat(); + dataFormat.setObjectMapper(mapper); + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) + } +} ---- ==== Using the Quarkus Jackson `ObjectMapper` with `JacksonDataFormat` @@ -24,18 +34,28 @@ The Quarkus Jackson extension exposes an `ObjectMapper` CDI bean which can be di [source,java] ---- -ObjectMapper mapper = new ObjectMapper(); -JacksonDataFormat dataFormat = new JacksonDataFormat(); -// Make JacksonDataFormat discover the Quarkus Jackson `ObjectMapper` from the Camel registry -dataFormat.setAutoDiscoverObjectMapper(true); +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + +public class Routes extends RouteBuilder { + public void configure() { + JacksonDataFormat dataFormat = new JacksonDataFormat(); + // Make JacksonDataFormat discover the Quarkus Jackson `ObjectMapper` from the Camel registry + dataFormat.setAutoDiscoverObjectMapper(true); + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) + } +} ---- If you are using the JSON binding mode in the Camel REST DSL and want to use the Quarkus Jackson `ObjectMapper`, it can be achieved as follows. [source,java] ---- +import org.apache.camel.builder.RouteBuilder; + @ApplicationScoped -public class Routes extends RouteBuilder() { +public class Routes extends RouteBuilder { public void configure() { restConfiguration().dataFormatProperty("autoDiscoverObjectMapper", "true"); // REST definition follows... @@ -47,6 +67,9 @@ You can perform customizations on the Quarkus `ObjectMapper` with a `ObjectMappe [source,java] ---- +import com.fasterxml.jackson.databind.ObjectMapper; +import io.quarkus.jackson.ObjectMapperCustomizer; + @Singleton public class RegisterCustomModuleCustomizer implements ObjectMapperCustomizer { public void customize(ObjectMapper mapper) { @@ -59,15 +82,20 @@ It's also possible to `@Inject` the Quarkus `ObjectMapper` and pass it to the `J [source,java] ---- +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; + @ApplicationScoped -public class Routes extends RouteBuilder() { +public class Routes extends RouteBuilder { @Inject ObjectMapper mapper; public void configure() { JacksonDataFormat dataFormat = new JacksonDataFormat(); dataFormat.setObjectMapper(mapper); - // Routes definition follows... + // Use the dataFormat instance in a route definition + from("direct:my-direct").marshal(dataFormat) } } ----