Skip to content

Commit 2e32f80

Browse files
committed
Merge branch '2.7.x'
2 parents 3de0245 + 8646ac4 commit 2e32f80

File tree

12 files changed

+35
-32
lines changed

12 files changed

+35
-32
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,4 +1003,7 @@ dependency-versions-coordinates=appendix.dependency-versions.coordinates
10031003
dependency-versions-properties=appendix.dependency-versions.properties
10041004

10051005
dependency-versions.coordinates=appendix.dependency-versions.coordinates
1006-
dependency-versions.properties=appendix.dependency-versions.properties
1006+
dependency-versions.properties=appendix.dependency-versions.properties
1007+
1008+
# gh-30405
1009+
web.servlet.spring-mvc.json=features.json.jackson.custom-serializers-and-deserializers

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/json.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@ Several configuration properties are provided for <<howto#howto.spring-mvc.custo
1818

1919

2020

21+
[[features.json.jackson.custom-serializers-and-deserializers]]
22+
==== Custom Serializers and Deserializers
23+
If you use Jackson to serialize and deserialize JSON data, you might want to write your own `JsonSerializer` and `JsonDeserializer` classes.
24+
Custom serializers are usually https://github.com/FasterXML/jackson-docs/wiki/JacksonHowToCustomSerializers[registered with Jackson through a module], but Spring Boot provides an alternative `@JsonComponent` annotation that makes it easier to directly register Spring Beans.
25+
26+
You can use the `@JsonComponent` annotation directly on `JsonSerializer`, `JsonDeserializer` or `KeyDeserializer` implementations.
27+
You can also use it on classes that contain serializers/deserializers as inner classes, as shown in the following example:
28+
29+
include::code:MyJsonComponent[]
30+
31+
All `@JsonComponent` beans in the `ApplicationContext` are automatically registered with Jackson.
32+
Because `@JsonComponent` is meta-annotated with `@Component`, the usual component-scanning rules apply.
33+
34+
Spring Boot also provides {spring-boot-module-code}/jackson/JsonObjectSerializer.java[`JsonObjectSerializer`] and {spring-boot-module-code}/jackson/JsonObjectDeserializer.java[`JsonObjectDeserializer`] base classes that provide useful alternatives to the standard Jackson versions when serializing objects.
35+
See {spring-boot-module-api}/jackson/JsonObjectSerializer.html[`JsonObjectSerializer`] and {spring-boot-module-api}/jackson/JsonObjectDeserializer.html[`JsonObjectDeserializer`] in the Javadoc for details.
36+
37+
The example above can be rewritten to use `JsonObjectSerializer`/`JsonObjectDeserializer` as follows:
38+
39+
include::code:object/MyJsonComponent[]
40+
41+
42+
2143
[[features.json.gson]]
2244
=== Gson
2345
Auto-configuration for Gson is provided.

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/reactive.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ If you need to add or customize codecs, you can create a custom `CodecCustomizer
7575

7676
include::code:MyCodecsConfiguration[]
7777

78-
You can also leverage <<web#web.servlet.spring-mvc.json,Boot's custom JSON serializers and deserializers>>.
78+
You can also leverage <<features#features.json.jackson.custom-serializers-and-deserializers,Boot's custom JSON serializers and deserializers>>.
7979

8080

8181

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,6 @@ You can also override default converters in the same way.
7575

7676

7777

78-
[[web.servlet.spring-mvc.json]]
79-
==== Custom JSON Serializers and Deserializers
80-
If you use Jackson to serialize and deserialize JSON data, you might want to write your own `JsonSerializer` and `JsonDeserializer` classes.
81-
Custom serializers are usually https://github.com/FasterXML/jackson-docs/wiki/JacksonHowToCustomSerializers[registered with Jackson through a module], but Spring Boot provides an alternative `@JsonComponent` annotation that makes it easier to directly register Spring Beans.
82-
83-
You can use the `@JsonComponent` annotation directly on `JsonSerializer`, `JsonDeserializer` or `KeyDeserializer` implementations.
84-
You can also use it on classes that contain serializers/deserializers as inner classes, as shown in the following example:
85-
86-
include::code:MyJsonComponent[]
87-
88-
All `@JsonComponent` beans in the `ApplicationContext` are automatically registered with Jackson.
89-
Because `@JsonComponent` is meta-annotated with `@Component`, the usual component-scanning rules apply.
90-
91-
Spring Boot also provides {spring-boot-module-code}/jackson/JsonObjectSerializer.java[`JsonObjectSerializer`] and {spring-boot-module-code}/jackson/JsonObjectDeserializer.java[`JsonObjectDeserializer`] base classes that provide useful alternatives to the standard Jackson versions when serializing objects.
92-
See {spring-boot-module-api}/jackson/JsonObjectSerializer.html[`JsonObjectSerializer`] and {spring-boot-module-api}/jackson/JsonObjectDeserializer.html[`JsonObjectDeserializer`] in the Javadoc for details.
93-
94-
The example above can be rewritten to use `JsonObjectSerializer`/`JsonObjectDeserializer` as follows:
95-
96-
include::code:object/MyJsonComponent[]
97-
98-
99-
10078
[[web.servlet.spring-mvc.message-codes]]
10179
==== MessageCodesResolver
10280
Spring MVC has a strategy for generating error codes for rendering error messages from binding errors: `MessageCodesResolver`.

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java renamed to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json;
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers;
1818

1919
import java.io.IOException;
2020

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.java renamed to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json;
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers;
1818

1919
class MyObject {
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json.object;
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.object;
1818

1919
import java.io.IOException;
2020

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.java renamed to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json.object;
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.object;
1818

1919
class MyObject {
2020

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.kt renamed to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers
1818

1919
import com.fasterxml.jackson.core.JsonGenerator
2020
import com.fasterxml.jackson.core.JsonParser

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.kt renamed to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers
1818

1919
class MyObject(val name: String = "", val age: Int = 0)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json.`object`
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.`object`
1818

1919
import com.fasterxml.jackson.core.JsonGenerator
2020
import com.fasterxml.jackson.core.JsonParser

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.kt renamed to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.web.servlet.springmvc.json.`object`
17+
package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.`object`
1818

1919
class MyObject(val name: String = "", val age: Int = 0)

0 commit comments

Comments
 (0)