Skip to content

Commit acab89f

Browse files
committed
Add Jackson2/3 to custom object mapper sections in docs.
See #1151 Signed-off-by: onobc <chris.bono@gmail.com>
1 parent fd75c31 commit acab89f

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/attributes/attributes-variables.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
:github: https://github.com/spring-projects/spring-pulsar
1010
:javadocs: https://docs.spring.io/spring-pulsar/docs/{spring-pulsar-version}/api
1111
:spring-framework-docs: https://spring.io/projects/spring-framework#learn
12-
:spring-boot-docs: https://docs.spring.io/spring-boot/docs/{spring-boot-version}/reference/htmlsingle
13-
:spring-boot-pulsar-config-props: {spring-boot-docs}/#application-properties.integration
12+
:spring-boot-docs: https://docs.spring.io/spring-boot/{spring-boot-version}
13+
:spring-boot-pulsar-config-props: {spring-boot-docs}/appendix/application-properties/index.html#appendix.application-properties.integration
1414
:spring-cloud-stream-docs: https://docs.spring.io/spring-cloud-stream/docs/{spring-cloud-stream-version}/reference/html/
1515
:spring-cloud-function: https://spring.io/projects/spring-cloud-function
1616

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/custom-object-mapper.adoc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[[custom-object-mapper]]
22
= Custom Object Mapper
3-
include::../attributes/attributes.adoc[]
3+
include::../attributes/attributes-variables.adoc[]
44

5-
Pulsar uses an internal Jackson `ObjectMapper` when de/serializing JSON messages.
6-
If you instead want to provide your own object mapper instance, you can register a `SchemaResolverCustomizer` and set your mapper on the `DefaultSchemaResolver` as follows:
5+
Pulsar uses an internal shaded Jackson `ObjectMapper` when de/serializing JSON messages.
6+
If you instead want to provide your own Jackson 2 object mapper instance, you can register a `SchemaResolverCustomizer` and set your mapper on the `DefaultSchemaResolver` as follows:
77

88
[source,java,indent=0,subs="verbatim"]
99
----
@@ -16,6 +16,8 @@ SchemaResolverCustomizer<DefaultSchemaResolver> schemaResolverCustomizer() {
1616
}
1717
----
1818

19+
IMPORTANT: The object mapper in the example above should be an instance of `com.fasterxml.jackson.databind.ObjectMapper`, **not** the shaded `org.apache.pulsar.shade.com.fasterxml.jackson.databind.ObjectMapper`.
20+
1921
This results in your object mapper being used to de/serialize all JSON messages that go through the schema resolution process (i.e. in cases where you do not pass a schema in directly when producing/consuming messages).
2022

2123
Under the hood, the resolver creates a special JSON schema which leverages the custom mapper and is used as the schema for all resolved JSON messages.
@@ -46,3 +48,13 @@ myObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
4648
4749
====
4850
NOTE: A later version of the framework may instead provide a customizer that operates on the default mapper rather than requiring a separate instance.
51+
52+
[[jackson2vs3]]
53+
== Jackson 2 / Jackson 3
54+
In Spring Boot 4 the default version of {spring-boot-docs}/reference/features/json.html#features.json.jackson[Jackson is 3] and is auto-configured via the spring-boot-starter-json module.
55+
However, Spring for Apache Pulsar expects a {spring-boot-docs}/reference/features/json.html#features.json.jackson2[Jackson 2] custom mapper.
56+
57+
If you are using Jackson 3 in your Spring Boot 4 application and want to use a custom mapper you will need to add Jackson 2 to the classpath.
58+
Don't worry, Spring Boot 4 allows Jackson 2 and 3 to co-exist in an application.
59+
60+
NOTE: A later version of the framework may support using a Jackson 2 or Jackson 3 custom mapper.

spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/pulsar-header.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ During inbound mapping, they are mapped as `String`.
4444
By default, only `org.springframework.util.MimeType` and `org.springframework.http.MediaType` are mapped this way.
4545

4646
===== Custom ObjectMapper
47-
The JSON mapper uses a reasonable configured Jasckson `ObjectMapper` to handle serialization of header values.
47+
The JSON mapper uses a reasonable configured Jackson 2 `ObjectMapper` to handle serialization of header values.
4848
However, to provide a custom object mapper one must simply provide an `ObjectMapper` bean with the name `pulsarHeaderObjectMapper`.
4949
For example:
5050
[source, java]
@@ -61,6 +61,10 @@ static class PulsarHeadersCustomObjectMapperTestConfig {
6161
}
6262
----
6363

64+
IMPORTANT: The object mapper in the example above should be an instance of `com.fasterxml.jackson.databind.ObjectMapper`, **not** the shaded `org.apache.pulsar.shade.com.fasterxml.jackson.databind.ObjectMapper`.
65+
66+
IMPORTANT: The xref:reference/custom-object-mapper.adoc#jackson2vs3[same limitations] regarding Jackson 2 vs. Jackson 3 apply here }
67+
6468
=== Inbound/Outbound Patterns
6569
On the inbound side, by default, all Pulsar headers (message metadata plus user properties) are mapped to `MessageHeaders`.
6670
On the outbound side, by default, all `MessageHeaders` are mapped, except `id`, `timestamp`, and the headers that represent the Pulsar message metadata (i.e. the headers that are prefixed with `pulsar_message_`).

0 commit comments

Comments
 (0)