Class StreamReadConstraints

  • All Implemented Interfaces:
    java.io.Serializable

    public class StreamReadConstraints
    extends java.lang.Object
    implements java.io.Serializable
    The constraints to use for streaming reads: used to guard against malicious input by preventing processing of "too big" input constructs (values, structures). Constraints are registered with TokenStreamFactory (such as JsonFactory); if nothing explicitly specified, default constraints are used.

    Currently constrained aspects, with default settings, are:

    Since:
    2.15
    See Also:
    Serialized Form
    • Constructor Detail

      • StreamReadConstraints

        @Deprecated
        protected StreamReadConstraints​(int maxNestingDepth,
                                        long maxDocLen,
                                        int maxNumLen,
                                        int maxStringLen)
        Deprecated.
      • StreamReadConstraints

        protected StreamReadConstraints​(int maxNestingDepth,
                                        long maxDocLen,
                                        int maxNumLen,
                                        int maxStringLen,
                                        int maxNameLen)
        Parameters:
        maxNestingDepth - Maximum input document nesting to allow
        maxDocLen - Maximum input document length to allow
        maxNumLen - Maximum number representation length to allow
        maxStringLen - Maximum String value length to allow
        maxNameLen - Maximum Object property name length to allow
        Since:
        2.16
    • Method Detail

      • overrideDefaultStreamReadConstraints

        public static void overrideDefaultStreamReadConstraints​(StreamReadConstraints streamReadConstraints)
        Override the default StreamReadConstraints. These defaults are only used when 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.

        Parameters:
        streamReadConstraints - new default for StreamReadConstraints (a null value will reset to built-in default)
        Since:
        v2.15.2
        See Also:
        defaults(), builder()
      • hasMaxDocumentLength

        public boolean hasMaxDocumentLength()
        Convenience method, basically same as:
          getMaxDocumentLength() > 0L
        
        Returns:
        True if this constraints instance has a limit for maximum document length to enforce; false otherwise.
      • validateNestingDepth

        public void validateNestingDepth​(int depth)
                                  throws StreamConstraintsException
        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.
        Parameters:
        depth - count of unclosed objects and arrays
        Throws:
        StreamConstraintsException - If depth exceeds maximum
      • validateDocumentLength

        public void validateDocumentLength​(long len)
                                    throws StreamConstraintsException
        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.
        Parameters:
        len - Current length of processed document content
        Throws:
        StreamConstraintsException - If length exceeds maximum
        Since:
        2.16
      • validateFPLength

        public void validateFPLength​(int length)
                              throws StreamConstraintsException
        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.
        Parameters:
        length - Length of number in input units
        Throws:
        StreamConstraintsException - If length exceeds maximum
      • validateIntegerLength

        public void validateIntegerLength​(int length)
                                   throws StreamConstraintsException
        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.
        Parameters:
        length - Length of number in input units
        Throws:
        StreamConstraintsException - If length exceeds maximum
      • validateStringLength

        public void validateStringLength​(int length)
                                  throws StreamConstraintsException
        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.
        Parameters:
        length - Length of string in input units
        Throws:
        StreamConstraintsException - If length exceeds maximum
      • validateNameLength

        public void validateNameLength​(int length)
                                throws StreamConstraintsException
        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.
        Parameters:
        length - Length of name in input units
        Throws:
        StreamConstraintsException - If length exceeds maximum
      • validateBigIntegerScale

        public void validateBigIntegerScale​(int scale)
                                     throws StreamConstraintsException
        Convenience method that can be used to verify that a conversion to BigInteger StreamConstraintsException is thrown.
        Parameters:
        scale - Scale (possibly negative) of BigDecimal to convert
        Throws:
        StreamConstraintsException - If magnitude (absolute value) of scale exceeds maximum allowed
      • _constrainRef

        protected java.lang.String _constrainRef​(java.lang.String method)