@@ -30,8 +30,31 @@ public class StreamWriteConstraints
30
30
31
31
protected final int _maxNestingDepth ;
32
32
33
- private static final StreamWriteConstraints DEFAULT =
34
- new StreamWriteConstraints (DEFAULT_MAX_DEPTH );
33
+ private static StreamWriteConstraints DEFAULT = new StreamWriteConstraints (DEFAULT_MAX_DEPTH );
34
+
35
+ /**
36
+ * Override the default StreamWriteConstraints. These defaults are only used when {@link JsonFactory}
37
+ * instances are not configured with their own StreamWriteConstraints.
38
+ * <p>
39
+ * Library maintainers should not set this as it will affect other code that uses Jackson.
40
+ * Library maintainers who want to configure StreamWriteConstraints for the Jackson usage within their
41
+ * lib should create <code>ObjectMapper</code> instances that have a {@link JsonFactory} instance with
42
+ * the required StreamWriteConstraints.
43
+ * <p>
44
+ * This method is meant for users delivering applications. If they use this, they set it when they start
45
+ * their application to avoid having other code initialize their mappers before the defaults are overridden.
46
+ *
47
+ * @param streamWriteConstraints new default for StreamWriteConstraints (a null value will reset to built-in default)
48
+ * @see #defaults()
49
+ * @see #builder()
50
+ */
51
+ public static void overrideDefaultStreamWriteConstraints (final StreamWriteConstraints streamWriteConstraints ) {
52
+ if (streamWriteConstraints == null ) {
53
+ DEFAULT = new StreamWriteConstraints (DEFAULT_MAX_DEPTH );
54
+ } else {
55
+ DEFAULT = streamWriteConstraints ;
56
+ }
57
+ }
35
58
36
59
public static final class Builder {
37
60
private int maxNestingDepth ;
@@ -84,6 +107,10 @@ public static Builder builder() {
84
107
return new Builder ();
85
108
}
86
109
110
+ /**
111
+ * @return the default {@link StreamWriteConstraints} (when none is set on the {@link JsonFactory} explicitly)
112
+ * @see #overrideDefaultStreamWriteConstraints(StreamWriteConstraints)
113
+ */
87
114
public static StreamWriteConstraints defaults () {
88
115
return DEFAULT ;
89
116
}
0 commit comments