public class StreamReadConstraints extends Object implements Serializable
TokenStreamFactory
(such as
JsonFactory
); if nothing explicitly specified, default
constraints are used.
Currently constrained aspects, with default settings, are:
DEFAULT_MAX_NUM_LEN
)
DEFAULT_MAX_STRING_LEN
)
DEFAULT_MAX_NAME_LEN
)
DEFAULT_MAX_DEPTH
)
unlimited
(coded as -1
,
(see DEFAULT_MAX_DOC_LEN
)
Modifier and Type | Class and Description |
---|---|
static class |
StreamReadConstraints.Builder |
Modifier and Type | Field and Description |
---|---|
protected long |
_maxDocLen |
protected int |
_maxNameLen |
protected int |
_maxNestingDepth |
protected int |
_maxNumLen |
protected int |
_maxStringLen |
static int |
DEFAULT_MAX_DEPTH
Default setting for maximum depth: see
StreamReadConstraints.Builder.maxNestingDepth(int) for details. |
static long |
DEFAULT_MAX_DOC_LEN
Default setting for maximum document length:
see
StreamReadConstraints.Builder.maxDocumentLength(long) for details. |
static int |
DEFAULT_MAX_NAME_LEN
Default setting for maximum name length: see
StreamReadConstraints.Builder.maxNameLength(int)
for details. |
static int |
DEFAULT_MAX_NUM_LEN |
static int |
DEFAULT_MAX_STRING_LEN
Default setting for maximum string length: see
StreamReadConstraints.Builder.maxStringLength(int)
for details. |
Modifier | Constructor and Description |
---|---|
protected |
StreamReadConstraints(int maxNestingDepth,
long maxDocLen,
int maxNumLen,
int maxStringLen)
Deprecated.
|
protected |
StreamReadConstraints(int maxNestingDepth,
long maxDocLen,
int maxNumLen,
int maxStringLen,
int maxNameLen) |
Modifier and Type | Method and Description |
---|---|
protected String |
_constrainRef(String method) |
protected StreamConstraintsException |
_constructException(String msgTemplate,
Object... args) |
static StreamReadConstraints.Builder |
builder() |
static StreamReadConstraints |
defaults() |
long |
getMaxDocumentLength()
Accessor for maximum document length.
|
int |
getMaxNameLength()
Accessor for maximum length of names to decode.
|
int |
getMaxNestingDepth()
Accessor for maximum depth.
|
int |
getMaxNumberLength()
Accessor for maximum length of numbers to decode.
|
int |
getMaxStringLength()
Accessor for maximum length of strings to decode.
|
boolean |
hasMaxDocumentLength()
Convenience method, basically same as:
|
static void |
overrideDefaultStreamReadConstraints(StreamReadConstraints streamReadConstraints)
Override the default StreamReadConstraints.
|
StreamReadConstraints.Builder |
rebuild() |
void |
validateBigIntegerScale(int scale)
Convenience method that can be used to verify that a conversion to
BigInteger
StreamConstraintsException
is thrown. |
void |
validateDocumentLength(long len)
Convenience method that can be used to verify that the
document length does not exceed the maximum specified by this
constraints object (if any): if it does, a
StreamConstraintsException
is thrown. |
void |
validateFPLength(int length)
Convenience method that can be used to verify that a floating-point
number of specified length does not exceed maximum specified by this
constraints object: if it does, a
StreamConstraintsException
is thrown. |
void |
validateIntegerLength(int length)
Convenience method that can be used to verify that an integer
number of specified length does not exceed maximum specific by this
constraints object: if it does, a
StreamConstraintsException
is thrown. |
void |
validateNameLength(int length)
Convenience method that can be used to verify that a name
of specified length does not exceed maximum specific by this
constraints object: if it does, a
StreamConstraintsException
is thrown. |
void |
validateNestingDepth(int depth)
Convenience method that can be used to verify that the
nesting depth does not exceed the maximum specified by this
constraints object: if it does, a
StreamConstraintsException
is thrown. |
void |
validateStringLength(int length)
Convenience method that can be used to verify that a String
of specified length does not exceed maximum specific by this
constraints object: if it does, a
StreamConstraintsException
is thrown. |
public static final int DEFAULT_MAX_DEPTH
StreamReadConstraints.Builder.maxNestingDepth(int)
for details.public static final long DEFAULT_MAX_DOC_LEN
StreamReadConstraints.Builder.maxDocumentLength(long)
for details.public static final int DEFAULT_MAX_NUM_LEN
public static final int DEFAULT_MAX_STRING_LEN
StreamReadConstraints.Builder.maxStringLength(int)
for details.
NOTE: Jackson 2.15.0 initially used a lower setting (5_000_000).
public static final int DEFAULT_MAX_NAME_LEN
StreamReadConstraints.Builder.maxNameLength(int)
for details.protected final int _maxNestingDepth
protected final long _maxDocLen
protected final int _maxNumLen
protected final int _maxStringLen
protected final int _maxNameLen
@Deprecated protected StreamReadConstraints(int maxNestingDepth, long maxDocLen, int maxNumLen, int maxStringLen)
protected StreamReadConstraints(int maxNestingDepth, long maxDocLen, int maxNumLen, int maxStringLen, int maxNameLen)
maxNestingDepth
- Maximum input document nesting to allowmaxDocLen
- Maximum input document length to allowmaxNumLen
- Maximum number representation length to allowmaxStringLen
- Maximum String value length to allowmaxNameLen
- Maximum Object property name length to allowpublic static void overrideDefaultStreamReadConstraints(StreamReadConstraints streamReadConstraints)
JsonFactory
instances are not configured with their own StreamReadConstraints.
Library maintainers should not set this as it will affect other code that uses Jackson.
Library maintainers who want to configure StreamReadConstraints for the Jackson usage within their
lib should create ObjectMapper
instances that have a JsonFactory
instance with
the required StreamReadConstraints.
This method is meant for users delivering applications. If they use this, they set it when they start their application to avoid having other code initialize their mappers before the defaults are overridden.
streamReadConstraints
- new default for StreamReadConstraints (a null value will reset to built-in default)defaults()
,
builder()
public static StreamReadConstraints.Builder builder()
public static StreamReadConstraints defaults()
StreamReadConstraints
(when none is set on the JsonFactory
explicitly)overrideDefaultStreamReadConstraints(com.fasterxml.jackson.core.StreamReadConstraints)
public StreamReadConstraints.Builder rebuild()
StreamReadConstraints.Builder
initialized with settings of this constraints
instancepublic int getMaxNestingDepth()
StreamReadConstraints.Builder.maxNestingDepth(int)
for details.public long getMaxDocumentLength()
StreamReadConstraints.Builder.maxDocumentLength(long)
for details.public boolean hasMaxDocumentLength()
getMaxDocumentLength() > 0L
True
if this constraints instance has a limit for maximum
document length to enforce; false
otherwise.public int getMaxNumberLength()
StreamReadConstraints.Builder.maxNumberLength(int)
for details.public int getMaxStringLength()
StreamReadConstraints.Builder.maxStringLength(int)
for details.public int getMaxNameLength()
StreamReadConstraints.Builder.maxNameLength(int)
for details.public void validateNestingDepth(int depth) throws StreamConstraintsException
StreamConstraintsException
is thrown.depth
- count of unclosed objects and arraysStreamConstraintsException
- If depth exceeds maximumpublic void validateDocumentLength(long len) throws StreamConstraintsException
StreamConstraintsException
is thrown.len
- Current length of processed document contentStreamConstraintsException
- If length exceeds maximumpublic void validateFPLength(int length) throws StreamConstraintsException
StreamConstraintsException
is thrown.length
- Length of number in input unitsStreamConstraintsException
- If length exceeds maximumpublic void validateIntegerLength(int length) throws StreamConstraintsException
StreamConstraintsException
is thrown.length
- Length of number in input unitsStreamConstraintsException
- If length exceeds maximumpublic void validateStringLength(int length) throws StreamConstraintsException
StreamConstraintsException
is thrown.length
- Length of string in input unitsStreamConstraintsException
- If length exceeds maximumpublic void validateNameLength(int length) throws StreamConstraintsException
StreamConstraintsException
is thrown.length
- Length of name in input unitsStreamConstraintsException
- If length exceeds maximumpublic void validateBigIntegerScale(int scale) throws StreamConstraintsException
BigInteger
StreamConstraintsException
is thrown.scale
- Scale (possibly negative) of BigDecimal
to convertStreamConstraintsException
- If magnitude (absolute value) of scale exceeds maximum
allowedprotected StreamConstraintsException _constructException(String msgTemplate, Object... args) throws StreamConstraintsException
StreamConstraintsException
Copyright © 2008–2024 FasterXML. All rights reserved.