Skip to content

Commit fb9f31d

Browse files
committed
Update reference documentation to use Jackson 3
Closes gh-35886
1 parent 4ee0a8e commit fb9f31d

File tree

15 files changed

+53
-64
lines changed

15 files changed

+53
-64
lines changed

framework-docs/modules/ROOT/pages/rsocket.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ Java::
237237
[source,java,indent=0,subs="verbatim,quotes"]
238238
----
239239
RSocketStrategies strategies = RSocketStrategies.builder()
240-
.encoders(encoders -> encoders.add(new Jackson2CborEncoder()))
241-
.decoders(decoders -> decoders.add(new Jackson2CborDecoder()))
240+
.encoders(encoders -> encoders.add(new JacksonCborEncoder()))
241+
.decoders(decoders -> decoders.add(new JacksonCborDecoder()))
242242
.build();
243243
244244
RSocketRequester requester = RSocketRequester.builder()
@@ -251,8 +251,8 @@ Kotlin::
251251
[source,kotlin,indent=0,subs="verbatim,quotes"]
252252
----
253253
val strategies = RSocketStrategies.builder()
254-
.encoders { it.add(Jackson2CborEncoder()) }
255-
.decoders { it.add(Jackson2CborDecoder()) }
254+
.encoders { it.add(JacksonCborEncoder()) }
255+
.decoders { it.add(JacksonCborDecoder()) }
256256
.build()
257257
258258
val requester = RSocketRequester.builder()
@@ -681,8 +681,8 @@ Java::
681681
@Bean
682682
public RSocketStrategies rsocketStrategies() {
683683
return RSocketStrategies.builder()
684-
.encoders(encoders -> encoders.add(new Jackson2CborEncoder()))
685-
.decoders(decoders -> decoders.add(new Jackson2CborDecoder()))
684+
.encoders(encoders -> encoders.add(new JacksonCborEncoder()))
685+
.decoders(decoders -> decoders.add(new JacksonCborDecoder()))
686686
.routeMatcher(new PathPatternRouteMatcher())
687687
.build();
688688
}
@@ -703,8 +703,8 @@ Kotlin::
703703
704704
@Bean
705705
fun rsocketStrategies() = RSocketStrategies.builder()
706-
.encoders { it.add(Jackson2CborEncoder()) }
707-
.decoders { it.add(Jackson2CborDecoder()) }
706+
.encoders { it.add(JacksonCborEncoder()) }
707+
.decoders { it.add(JacksonCborDecoder()) }
708708
.routeMatcher(PathPatternRouteMatcher())
709709
.build()
710710
}

framework-docs/modules/ROOT/pages/web/webflux-functional.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,14 @@ Java::
374374
+
375375
[source,java]
376376
----
377-
ServerResponse.ok().hint(Jackson2CodecSupport.JSON_VIEW_HINT, MyJacksonView.class).body(...);
377+
ServerResponse.ok().hint(JacksonCodecSupport.JSON_VIEW_HINT, MyJacksonView.class).body(...);
378378
----
379379
380380
Kotlin::
381381
+
382382
[source,kotlin]
383383
----
384-
ServerResponse.ok().hint(Jackson2CodecSupport.JSON_VIEW_HINT, MyJacksonView::class.java).body(...)
384+
ServerResponse.ok().hint(JacksonCodecSupport.JSON_VIEW_HINT, MyJacksonView::class.java).body(...)
385385
----
386386
======
387387

framework-docs/modules/ROOT/pages/web/webflux-view.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ purposes, it is useful to be able to alternate between rendering a model with an
482482
or as other formats (such as JSON or XML), depending on the content type requested by the client.
483483
To support doing so, Spring WebFlux provides the `HttpMessageWriterView`, which you can use to
484484
plug in any of the available xref:web/webflux/reactive-spring.adoc#webflux-codecs[Codecs] from
485-
`spring-web`, such as `Jackson2JsonEncoder`, `Jackson2SmileEncoder`, or `Jaxb2XmlEncoder`.
485+
`spring-web`, such as `JacksonJsonEncoder`, `JacksonSmileEncoder`, or `Jaxb2XmlEncoder`.
486486

487487
Unlike other view technologies, `HttpMessageWriterView` does not require a `ViewResolver` but is
488488
instead xref:web/webflux/config.adoc#webflux-config-view-resolvers[configured] as a default view.

framework-docs/modules/ROOT/pages/web/webflux/config.adoc

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,8 @@ Kotlin::
334334
`ServerCodecConfigurer` provides a set of default readers and writers. You can use it to add
335335
more readers and writers, customize the default ones, or replace the default ones completely.
336336

337-
For Jackson JSON and XML, consider using
338-
{spring-framework-api}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`],
339-
which customizes Jackson's default properties with the following ones:
340-
341-
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled.
342-
* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled.
343-
344-
It also automatically registers the following well-known modules if they are detected on the classpath:
345-
346-
* {jackson-github-org}/jackson-datatype-jsr310[`jackson-datatype-jsr310`]: Support for Java 8 Date and Time API types.
347-
* {jackson-github-org}/jackson-datatype-jdk8[`jackson-datatype-jdk8`]: Support for other Java 8 types, such as `Optional`.
348-
* {jackson-github-org}/jackson-module-kotlin[`jackson-module-kotlin`]: Support for Kotlin classes and data classes.
349-
337+
For Jackson, consider using a Jackson format-specific builder like `JsonMapper.Builder` to configure Jackson's default
338+
properties.
350339

351340
[[webflux-config-view-resolvers]]
352341
== View Resolvers
@@ -489,7 +478,7 @@ Java::
489478
public void configureViewResolvers(ViewResolverRegistry registry) {
490479
registry.freeMarker();
491480
492-
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
481+
JacksonJsonEncoder encoder = new JacksonJsonEncoder();
493482
registry.defaultViews(new HttpMessageWriterView(encoder));
494483
}
495484
@@ -508,7 +497,7 @@ Kotlin::
508497
override fun configureViewResolvers(registry: ViewResolverRegistry) {
509498
registry.freeMarker()
510499
511-
val encoder = Jackson2JsonEncoder()
500+
val encoder = JacksonJsonEncoder()
512501
registry.defaultViews(HttpMessageWriterView(encoder))
513502
}
514503

framework-docs/modules/ROOT/pages/web/webflux/reactive-spring.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,35 +459,35 @@ xref:web/webflux/config.adoc#webflux-config-message-codecs[HTTP message codecs].
459459
JSON and binary JSON ({jackson-github-org}/smile-format-specification[Smile]) are
460460
both supported when the Jackson library is present.
461461

462-
The `Jackson2Decoder` works as follows:
462+
The `JacksonJsonDecoder` works as follows:
463463

464464
* Jackson's asynchronous, non-blocking parser is used to aggregate a stream of byte chunks
465465
into ``TokenBuffer``'s each representing a JSON object.
466-
* Each `TokenBuffer` is passed to Jackson's `ObjectMapper` to create a higher level object.
466+
* Each `TokenBuffer` is passed to Jackson's `JsonMapper` to create a higher level object.
467467
* When decoding to a single-value publisher (for example, `Mono`), there is one `TokenBuffer`.
468468
* When decoding to a multi-value publisher (for example, `Flux`), each `TokenBuffer` is passed to
469-
the `ObjectMapper` as soon as enough bytes are received for a fully formed object. The
469+
the `JsonMapper` as soon as enough bytes are received for a fully formed object. The
470470
input content can be a JSON array, or any
471471
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] format such as NDJSON,
472472
JSON Lines, or JSON Text Sequences.
473473

474-
The `Jackson2Encoder` works as follows:
474+
The `JacksonJsonEncoder` works as follows:
475475

476476
* For a single value publisher (for example, `Mono`), simply serialize it through the
477-
`ObjectMapper`.
477+
`JsonMapper`.
478478
* For a multi-value publisher with `application/json`, by default collect the values with
479479
`Flux#collectToList()` and then serialize the resulting collection.
480480
* For a multi-value publisher with a streaming media type such as
481481
`application/x-ndjson` or `application/stream+x-jackson-smile`, encode, write, and
482482
flush each value individually using a
483483
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] format. Other
484484
streaming media types may be registered with the encoder.
485-
* For SSE the `Jackson2Encoder` is invoked per event and the output is flushed to ensure
485+
* For SSE the `JacksonJsonEncoder` is invoked per event and the output is flushed to ensure
486486
delivery without delay.
487487

488488
[NOTE]
489489
====
490-
By default both `Jackson2Encoder` and `Jackson2Decoder` do not support elements of type
490+
By default both `JacksonJsonEncoder` and `JacksonJsonDecoder` do not support elements of type
491491
`String`. Instead the default assumption is that a string or a sequence of strings
492492
represent serialized JSON content, to be rendered by the `CharSequenceEncoder`. If what
493493
you need is to render a JSON array from `Flux<String>`, use `Flux#collectToList()` and

framework-docs/modules/ROOT/pages/web/webmvc-view/mvc-jackson.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ Spring offers support for the Jackson JSON library.
1010
== Jackson-based JSON MVC Views
1111
[.small]#xref:web/webflux-view.adoc#webflux-view-httpmessagewriter[See equivalent in the Reactive stack]#
1212

13-
The `MappingJackson2JsonView` uses the Jackson library's `ObjectMapper` to render the response
13+
The `JacksonJsonView` uses the Jackson library's `JsonMapper` to render the response
1414
content as JSON. By default, the entire contents of the model map (with the exception of
1515
framework-specific classes) are encoded as JSON. For cases where the contents of the
1616
map need to be filtered, you can specify a specific set of model attributes to encode
1717
by using the `modelKeys` property. You can also use the `extractValueFromSingleKeyModel`
1818
property to have the value in single-key models extracted and serialized directly rather
1919
than as a map of model attributes.
2020

21-
You can customize JSON mapping as needed by using Jackson's provided
22-
annotations. When you need further control, you can inject a custom `ObjectMapper`
23-
through the `ObjectMapper` property, for cases where you need to provide custom JSON
24-
serializers and deserializers for specific types.
21+
You can customize JSON mapping as needed by using Jackson's provided annotations. When
22+
you need further control, you can inject a custom `JsonMapper` through the `JsonMapper`
23+
or `JsonMapper.Builder` constructor parameters, for cases where you need to provide
24+
custom JSON serializers and deserializers for specific types.
2525

2626

2727
[[mvc-view-xml-mapping]]
2828
== Jackson-based XML Views
2929
[.small]#xref:web/webflux-view.adoc#webflux-view-httpmessagewriter[See equivalent in the Reactive stack]#
3030

31-
`MappingJackson2XmlView` uses the
31+
`JacksonXmlView` uses the
3232
{jackson-github-org}/jackson-dataformat-xml[Jackson XML extension's] `XmlMapper`
3333
to render the response content as XML. If the model contains multiple entries, you should
3434
explicitly set the object to be serialized by using the `modelKey` bean property. If the
3535
model contains a single entry, it is serialized automatically.
3636

3737
You can customize XML mapping as needed by using JAXB or Jackson's provided
3838
annotations. When you need further control, you can inject a custom `XmlMapper`
39-
through the `ObjectMapper` property, for cases where custom XML
40-
you need to provide serializers and deserializers for specific types.
39+
created via `XmlMapper.Builder` for cases where custom XML you need to provide
40+
serializers and deserializers for specific types.

framework-docs/modules/ROOT/pages/web/webmvc/message-converters.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,25 @@ This converter requires a `Marshaller` and `Unmarshaller` before it can be used.
4242
You can inject these through constructor or bean properties.
4343
By default, this converter supports `text/xml` and `application/xml`.
4444

45-
| `MappingJackson2HttpMessageConverter`
46-
| An `HttpMessageConverter` implementation that can read and write JSON by using Jackson's `ObjectMapper`.
45+
| `JacksonJsonHttpMessageConverter`
46+
| An `HttpMessageConverter` implementation that can read and write JSON by using Jackson's `JsonMapper`.
4747
You can customize JSON mapping as needed through the use of Jackson's provided annotations.
48-
When you need further control (for cases where custom JSON serializers/deserializers need to be provided for specific types), you can inject a custom `ObjectMapper` through the `ObjectMapper` property.
49-
By default, this converter supports `application/json`. This requires the `com.fasterxml.jackson.core:jackson-databind` dependency.
48+
When you need further control (for cases where custom JSON serializers/deserializers need to be provided for specific types), you can inject a custom `JsonMapper` through the `JsonMapper` or `JsonMapper.Builder ` constructor parameters.
49+
By default, this converter supports `application/json`. This requires the `tools.jackson.core:jackson-databind` dependency.
5050

51-
| `MappingJackson2XmlHttpMessageConverter`
51+
| `JacksonXmlHttpMessageConverter`
5252
| An `HttpMessageConverter` implementation that can read and write XML by using {jackson-github-org}/jackson-dataformat-xml[Jackson XML] extension's `XmlMapper`.
5353
You can customize XML mapping as needed through the use of JAXB or Jackson's provided annotations.
54-
When you need further control (for cases where custom XML serializers/deserializers need to be provided for specific types), you can inject a custom `XmlMapper` through the `ObjectMapper` property.
55-
By default, this converter supports `application/xml`. This requires the `com.fasterxml.jackson.dataformat:jackson-dataformat-xml` dependency.
54+
When you need further control (for cases where custom XML serializers/deserializers need to be provided for specific types), you can inject a custom `XmlMapper` through the `JsonMapper` or `JsonMapper.Builder` constructor parameters.
55+
By default, this converter supports `application/xml`. This requires the `tools.jackson.dataformat:jackson-dataformat-xml` dependency.
5656

5757
| `KotlinSerializationJsonHttpMessageConverter`
5858
| An `HttpMessageConverter` implementation that can read and write JSON using `kotlinx.serialization`.
5959
This converter is not configured by default, as this conflicts with Jackson.
6060
Developers must configure it as an additional converter ahead of the Jackson one.
6161

62-
| `MappingJackson2CborHttpMessageConverter`
63-
| `com.fasterxml.jackson.dataformat:jackson-dataformat-cbor`
62+
| `JacksonCborHttpMessageConverter`
63+
| `tools.jackson.dataformat:jackson-dataformat-cbor`
6464

6565
| `SourceHttpMessageConverter`
6666
| An `HttpMessageConverter` implementation that can read and write `javax.xml.transform.Source` from the HTTP request and response.

framework-docs/src/main/java/org/springframework/docs/testing/mockmvc/assertj/mockmvctestersetup/converter/AccountControllerIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.docs.testing.mockmvc.assertj.mockmvctestersetup.ApplicationWebConfiguration;
23-
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
23+
import org.springframework.http.converter.AbstractJacksonHttpMessageConverter ;
2424
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
2525
import org.springframework.test.web.servlet.assertj.MockMvcTester;
2626
import org.springframework.web.context.WebApplicationContext;
@@ -34,7 +34,7 @@ class AccountControllerIntegrationTests {
3434

3535
AccountControllerIntegrationTests(@Autowired WebApplicationContext wac) {
3636
this.mockMvc = MockMvcTester.from(wac).withHttpMessageConverters(
37-
List.of(wac.getBean(AbstractJackson2HttpMessageConverter.class)));
37+
List.of(wac.getBean(AbstractJacksonHttpMessageConverter.class)));
3838
}
3939

4040
// ...

framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/FreeMarkerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
2222
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2323
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
24-
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
24+
import org.springframework.web.servlet.view.json.JacksonJsonView;
2525

2626
@SuppressWarnings("removal")
2727
// tag::snippet[]
@@ -30,7 +30,7 @@ public class FreeMarkerConfiguration implements WebMvcConfigurer {
3030

3131
@Override
3232
public void configureViewResolvers(ViewResolverRegistry registry) {
33-
registry.enableContentNegotiation(new MappingJackson2JsonView());
33+
registry.enableContentNegotiation(new JacksonJsonView());
3434
registry.freeMarker().cache(false);
3535
}
3636

framework-docs/src/main/java/org/springframework/docs/web/webmvc/mvcconfig/mvcconfigviewresolvers/WebConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.springframework.context.annotation.Configuration;
2020
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
2121
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
22-
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
22+
import org.springframework.web.servlet.view.json.JacksonJsonView;
2323

2424
@SuppressWarnings("removal")
2525
// tag::snippet[]
@@ -28,7 +28,7 @@ public class WebConfiguration implements WebMvcConfigurer {
2828

2929
@Override
3030
public void configureViewResolvers(ViewResolverRegistry registry) {
31-
registry.enableContentNegotiation(new MappingJackson2JsonView());
31+
registry.enableContentNegotiation(new JacksonJsonView());
3232
registry.jsp();
3333
}
3434
}

0 commit comments

Comments
 (0)