From 8646ac4215c787f7119b9c8bb239bfd15876c009 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 25 Mar 2022 13:30:06 +0000 Subject: [PATCH] Move JsonComponent docs to general Jackson section Closes gh-30405 --- .../docs/asciidoc/anchor-rewrite.properties | 5 ++++- .../src/docs/asciidoc/features/json.adoc | 22 +++++++++++++++++++ .../src/docs/asciidoc/web/reactive.adoc | 2 +- .../src/docs/asciidoc/web/servlet.adoc | 22 ------------------- .../MyJsonComponent.java | 2 +- .../MyObject.java | 2 +- .../object/MyJsonComponent.java | 2 +- .../object/MyObject.java | 2 +- .../MyJsonComponent.kt | 2 +- .../MyObject.kt | 2 +- .../object/MyJsonComponent.kt | 2 +- .../object/MyObject.kt | 2 +- 12 files changed, 35 insertions(+), 32 deletions(-) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/MyJsonComponent.java (95%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/MyObject.java (88%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/object/MyJsonComponent.java (94%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/object/MyObject.java (88%) rename spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/MyJsonComponent.kt (95%) rename spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/MyObject.kt (87%) rename spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/object/MyJsonComponent.kt (94%) rename spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/{web/servlet/springmvc/json => features/json/jackson/customserializersanddeserializers}/object/MyObject.kt (86%) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties index e3dfb57564c..012ddf5363b 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/anchor-rewrite.properties @@ -1012,4 +1012,7 @@ dependency-versions-coordinates=appendix.dependency-versions.coordinates dependency-versions-properties=appendix.dependency-versions.properties dependency-versions.coordinates=appendix.dependency-versions.coordinates -dependency-versions.properties=appendix.dependency-versions.properties \ No newline at end of file +dependency-versions.properties=appendix.dependency-versions.properties + +# gh-30405 +web.servlet.spring-mvc.json=features.json.jackson.custom-serializers-and-deserializers \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/json.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/json.adoc index e3f82ba9c82..f11989c0a8b 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/json.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/json.adoc @@ -18,6 +18,28 @@ Several configuration properties are provided for <>. +You can also leverage <>. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc index 82d895530ad..c81b30688d6 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc @@ -75,28 +75,6 @@ You can also override default converters in the same way. -[[web.servlet.spring-mvc.json]] -==== Custom JSON Serializers and Deserializers -If you use Jackson to serialize and deserialize JSON data, you might want to write your own `JsonSerializer` and `JsonDeserializer` classes. -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. - -You can use the `@JsonComponent` annotation directly on `JsonSerializer`, `JsonDeserializer` or `KeyDeserializer` implementations. -You can also use it on classes that contain serializers/deserializers as inner classes, as shown in the following example: - -include::code:MyJsonComponent[] - -All `@JsonComponent` beans in the `ApplicationContext` are automatically registered with Jackson. -Because `@JsonComponent` is meta-annotated with `@Component`, the usual component-scanning rules apply. - -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. -See {spring-boot-module-api}/jackson/JsonObjectSerializer.html[`JsonObjectSerializer`] and {spring-boot-module-api}/jackson/JsonObjectDeserializer.html[`JsonObjectDeserializer`] in the Javadoc for details. - -The example above can be rewritten to use `JsonObjectSerializer`/`JsonObjectDeserializer` as follows: - -include::code:object/MyJsonComponent[] - - - [[web.servlet.spring-mvc.message-codes]] ==== MessageCodesResolver Spring MVC has a strategy for generating error codes for rendering error messages from binding errors: `MessageCodesResolver`. diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.java similarity index 95% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.java index 23b35fd0a05..21e66b707ee 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json; +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers; import java.io.IOException; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.java index 5629243c262..5809e80f3c4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json; +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers; class MyObject { diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.java similarity index 94% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.java index 0334517d05d..b62f57c7597 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json.object; +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.object; import java.io.IOException; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.java similarity index 88% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.java index 02ce4617794..2a417a65301 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json.object; +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.object; class MyObject { diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.kt similarity index 95% rename from spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.kt rename to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.kt index 63acd96853a..dfa9e793d7c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyJsonComponent.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyJsonComponent.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParser diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.kt similarity index 87% rename from spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.kt rename to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.kt index 66df4a49b3d..71d1cb4f25c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/MyObject.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/MyObject.kt @@ -14,6 +14,6 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers class MyObject(val name: String = "", val age: Int = 0) diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.kt similarity index 94% rename from spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.kt rename to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.kt index 5a4268d67db..14f13980af9 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyJsonComponent.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyJsonComponent.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json.`object` +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.`object` import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonParser diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.kt similarity index 86% rename from spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.kt rename to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.kt index 08e5296a0ce..e049491df50 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/json/object/MyObject.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/json/jackson/customserializersanddeserializers/object/MyObject.kt @@ -14,6 +14,6 @@ * limitations under the License. */ -package org.springframework.boot.docs.web.servlet.springmvc.json.`object` +package org.springframework.boot.docs.features.json.jackson.customserializersanddeserializers.`object` class MyObject(val name: String = "", val age: Int = 0)