diff --git a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java index a454c38d0c..3e45dfb10e 100644 --- a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java +++ b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java @@ -156,8 +156,12 @@ public class ProblemDetail { /** * Set a "dynamic" property to be added to a generic {@link #getProperties() * properties map}. + *

When Jackson JSON is present on the classpath, any properties set here + * are rendered as top level key-value pairs in the output JSON. Otherwise, + * they are rendered as a {@code "properties"} sub-map. * @param name the property name * @param value the property value + * @see org.springframework.http.converter.json.ProblemDetailJacksonMixin */ public void setProperty(String name, Object value) { this.properties = (this.properties != null ? this.properties : new LinkedHashMap<>()); @@ -214,6 +218,10 @@ public class ProblemDetail { * Return a generic map of properties that are not known ahead of time, * possibly {@code null} if no properties have been added. To add a property, * use {@link #setProperty(String, Object)}. + *

When Jackson JSON is present on the classpath, the content of this map + * is unwrapped and rendered as top level key-value pairs in the output JSON. + * Otherwise, they are rendered as a {@code "properties"} sub-map. + * @see org.springframework.http.converter.json.ProblemDetailJacksonMixin */ @Nullable public Map getProperties() { diff --git a/src/docs/asciidoc/web/webflux.adoc b/src/docs/asciidoc/web/webflux.adoc index 580d7cb63d..3a9695e1a4 100644 --- a/src/docs/asciidoc/web/webflux.adoc +++ b/src/docs/asciidoc/web/webflux.adoc @@ -3525,9 +3525,9 @@ back on "application/problem+json". Applications can extend `ProblemDetail` with non-standard fields in one of two ways: -. Add properties to the generic `properties` map in `ProblemDetail`. When using -the Jackson library, this `properties` map is unwrapped and as top level JSON -properties with the help of `ProblemDetailJacksonMixin`. +. Add properties to the generic `properties` map in `ProblemDetail`. When the Jackson JSON +library is present, this `properties` map is unwrapped and rendered as top level +key-value pairs in the output JSON, with the help of `ProblemDetailJacksonMixin`. . Create a `ProblemDetail` subclass that defines the extra, non-standard fields. Subclasses can use a protected copy constructor in order to re-create an existing `ProblemDetail` as a subclass. This can be done centrally from an `@ControllerAdvice`