@@ -57,9 +57,34 @@ public class StreamReadConstraints
57
57
protected final int _maxNumLen ;
58
58
protected final int _maxStringLen ;
59
59
60
- private static final StreamReadConstraints DEFAULT =
60
+ private static StreamReadConstraints DEFAULT =
61
61
new StreamReadConstraints (DEFAULT_MAX_DEPTH , DEFAULT_MAX_NUM_LEN , DEFAULT_MAX_STRING_LEN );
62
62
63
+ /**
64
+ * Override the default StreamReadConstraints. These defaults are only used when {@link JsonFactory}
65
+ * instances are not configured with their own StreamReadConstraints.
66
+ * <p>
67
+ * Library maintainers should not set this as it will affect other code that uses Jackson.
68
+ * Library maintainers who want to configure StreamReadConstraints for the Jackson usage within their
69
+ * lib should create <code>ObjectMapper</code> instances that have a {@link JsonFactory} instance with
70
+ * the required StreamReadConstraints.
71
+ * <p>
72
+ * This method is meant for users delivering applications. If they use this, they set it when they start
73
+ * their application to avoid having other code initialize their mappers before the defaults are overridden.
74
+ *
75
+ * @param streamReadConstraints new default for StreamReadConstraints (a null value will reset to built-in default)
76
+ * @see #defaults()
77
+ * @see #builder()
78
+ * @since v2.15.2
79
+ */
80
+ public static void overrideDefaultStreamReadConstraints (final StreamReadConstraints streamReadConstraints ) {
81
+ if (streamReadConstraints == null ) {
82
+ DEFAULT = new StreamReadConstraints (DEFAULT_MAX_DEPTH , DEFAULT_MAX_NUM_LEN , DEFAULT_MAX_STRING_LEN );
83
+ } else {
84
+ DEFAULT = streamReadConstraints ;
85
+ }
86
+ }
87
+
63
88
public static final class Builder {
64
89
private int maxNestingDepth ;
65
90
private int maxNumLen ;
@@ -161,6 +186,10 @@ public static Builder builder() {
161
186
return new Builder ();
162
187
}
163
188
189
+ /**
190
+ * @return the default {@link StreamReadConstraints} (when none is set on the {@link JsonFactory} explicitly)
191
+ * @see #overrideDefaultStreamReadConstraints
192
+ */
164
193
public static StreamReadConstraints defaults () {
165
194
return DEFAULT ;
166
195
}
0 commit comments