com.fasterxml.jackson.core

## Class StreamWriteConstraints

- java.lang.Object
- - com.fasterxml.jackson.core.StreamWriteConstraints

All Implemented Interfaces:
  Serializable

    public class StreamWriteConstraints
    extends Object
    implements Serializable

The constraints to use for streaming writes: used to guard against problematic output by preventing processing of "too big" output 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:

- Maximum Nesting depth: default 1000 (see `DEFAULT_MAX_DEPTH`)

Since:
  2.16
See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`static class` `StreamWriteConstraints.Builder`

### Field Summary

Fields
`protected int` `_maxNestingDepth`
`static int` `DEFAULT_MAX_DEPTH` Default setting for maximum depth: see `StreamWriteConstraints.Builder.maxNestingDepth(int)` for details.

### Constructor Summary

Constructors
`protected` `StreamWriteConstraints(int maxNestingDepth)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected String` `_constrainRef(String method)`
`protected StreamConstraintsException` `_constructException(String msgTemplate, Object... args)`
`static StreamWriteConstraints.Builder` `builder()`
`static StreamWriteConstraints` `defaults()`
`int` `getMaxNestingDepth()` Accessor for maximum depth.
`static void` `overrideDefaultStreamWriteConstraints(StreamWriteConstraints streamWriteConstraints)` Override the default StreamWriteConstraints.
`StreamWriteConstraints.Builder` `rebuild()`
`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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_MAX_DEPTH

    public static final int DEFAULT_MAX_DEPTH

Default setting for maximum depth: see `StreamWriteConstraints.Builder.maxNestingDepth(int)` for details.

See Also:
  Constant Field Values

#### _maxNestingDepth

    protected final int _maxNestingDepth

### Constructor Detail

#### StreamWriteConstraints

    protected StreamWriteConstraints(int maxNestingDepth)

### Method Detail

#### overrideDefaultStreamWriteConstraints

    public static void overrideDefaultStreamWriteConstraints(StreamWriteConstraints streamWriteConstraints)

Override the default StreamWriteConstraints. These defaults are only used when `JsonFactory` instances are not configured with their own StreamWriteConstraints.

Library maintainers should not set this as it will affect other code that uses Jackson. Library maintainers who want to configure StreamWriteConstraints for the Jackson usage within their lib should create `ObjectMapper` instances that have a `JsonFactory` instance with the required StreamWriteConstraints.

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:
  `streamWriteConstraints` - new default for StreamWriteConstraints (a null value will reset to built-in default)
See Also:
  `defaults()`, `builder()`

#### builder

    public static StreamWriteConstraints.Builder builder()

#### defaults

    public static StreamWriteConstraints defaults()

Returns:
  the default `StreamWriteConstraints` (when none is set on the `JsonFactory` explicitly)
See Also:
  `overrideDefaultStreamWriteConstraints(StreamWriteConstraints)`

#### rebuild

    public StreamWriteConstraints.Builder rebuild()

Returns:
  New `StreamWriteConstraints.Builder` initialized with settings of this constraints instance

#### getMaxNestingDepth

    public int getMaxNestingDepth()

Accessor for maximum depth. see `StreamWriteConstraints.Builder.maxNestingDepth(int)` for details.

Returns:
  Maximum allowed depth

#### 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

#### _constructException

    protected StreamConstraintsException _constructException(String msgTemplate,
                                                             Object... args)
                                                      throws StreamConstraintsException

Throws:
  `StreamConstraintsException`

#### _constrainRef

    protected String _constrainRef(String method)