Class LimitingStream

java.lang.Object
io.micronaut.serde.LimitingStream
Direct Known Subclasses:
AbstractStreamDecoder, BsonWriterEncoder, JacksonDecoder, JacksonEncoder, JsonNodeDecoder, JsonNodeEncoder, OracleJdbcJsonGeneratorEncoder

@Internal public abstract class LimitingStream extends Object
Utility class to check data limits in encoders and decoders. Currently, the only limit that is checked is the nesting depth.

This class can be used in both implementation "patterns" for Encoder (and Decoder): For the same-object pattern, where Encoder.encodeObject(Argument) returns the same instance, the encoder should call increaseDepth(), with a corresponding decreaseDepth() call in Encoder.finishStructure(). Conversely, if the encoder is implemented using the child-object pattern, where Encoder.encodeObject(Argument) returns a child encoder responsible for the subtree, that child encoder should be instantiated using the new limits returned by childLimits().

If there is a limit violation, childLimits() or increaseDepth() will throw an exception.

Since:
2.0.0
Author:
Jonas Konrad
  • Field Details

  • Constructor Details

  • Method Details

    • ourLimits

      @NonNull protected final @NonNull LimitingStream.RemainingLimits ourLimits()
      Get a snapshot of our current limits to be passed to the constructor. This can be used for buffering decoders, when a new decoder takes over but no change in depth takes place.
      Returns:
      The current limits
    • childLimits

      @NonNull protected final @NonNull LimitingStream.RemainingLimits childLimits() throws SerdeException
      Get the limits of a new child encoder.
      Returns:
      The new limits
      Throws:
      SerdeException - If there is a nesting depth limit violation
    • increaseDepth

      protected final void increaseDepth() throws SerdeException
      Increase the current depth.
      Throws:
      SerdeException - If there is a nesting depth limit violation
    • decreaseDepth

      protected final void decreaseDepth()
      Decrease the current depth, always needs a corresponding increaseDepth() call.
    • limitsFromConfiguration

      public static LimitingStream.RemainingLimits limitsFromConfiguration(SerdeConfiguration configuration)
      Get the configured limits.
      Parameters:
      configuration - The serde configuration
      Returns:
      The configured limits