17
17
package org .springframework .http ;
18
18
19
19
import java .net .URI ;
20
+ import java .util .LinkedHashMap ;
21
+ import java .util .Map ;
20
22
21
23
import org .springframework .lang .Nullable ;
22
24
import org .springframework .util .Assert ;
@@ -54,6 +56,9 @@ public class ProblemDetail {
54
56
@ Nullable
55
57
private URI instance ;
56
58
59
+ @ Nullable
60
+ private Map <String , Object > properties ;
61
+
57
62
58
63
/**
59
64
* Protected constructor for subclasses.
@@ -75,6 +80,7 @@ protected ProblemDetail(ProblemDetail other) {
75
80
this .status = other .status ;
76
81
this .detail = other .detail ;
77
82
this .instance = other .instance ;
83
+ this .properties = (other .properties != null ? new LinkedHashMap <>(other .properties ) : null );
78
84
}
79
85
80
86
/**
@@ -201,6 +207,18 @@ public void setInstance(@Nullable URI instance) {
201
207
this .instance = instance ;
202
208
}
203
209
210
+ /**
211
+ * Set a "dynamic" property to be added to a generic {@link #getProperties()
212
+ * properties map}.
213
+ * @param name the property name
214
+ * @param value the property value
215
+ */
216
+ public void setProperty (String name , Object value ) {
217
+ this .properties = (this .properties != null ? this .properties : new LinkedHashMap <>());
218
+ this .properties .put (name , value );
219
+ }
220
+
221
+
204
222
205
223
// Getters
206
224
@@ -249,6 +267,14 @@ public URI getInstance() {
249
267
return this .instance ;
250
268
}
251
269
270
+ /**
271
+ * Return a generic map of properties that are not known ahead of time.
272
+ */
273
+ @ Nullable
274
+ public Map <String , Object > getProperties () {
275
+ return this .properties ;
276
+ }
277
+
252
278
253
279
@ Override
254
280
public String toString () {
@@ -264,7 +290,8 @@ protected String initToStringContent() {
264
290
", title='" + getTitle () + "'" +
265
291
", status=" + getStatus () +
266
292
", detail='" + getDetail () + "'" +
267
- ", instance='" + getInstance () + "'" ;
293
+ ", instance='" + getInstance () + "'" +
294
+ ", properties='" + getProperties () + "'" ;
268
295
}
269
296
270
297
0 commit comments