Class CoercionPolicy

java.lang.Object
io.micronaut.serde.config.CoercionPolicy

public final class CoercionPolicy extends Object
The scalar coercions a Decoder is allowed to perform, resolved once from the DeserializationConfiguration and then passed to every decoder that is created, in the same way as LimitingStream.RemainingLimits.

A decoder that is handed a policy must consult it at every point where it reads a value whose JSON shape does not match the requested type, and must pass its own policy on to the decoders it creates, in particular in Decoder.decodeBuffer(), so that the same input is accepted or rejected no matter which decoder ends up reading it.

Since:
3.2
Author:
Denis Stepanov
  • Field Details

    • LENIENT

      public static final CoercionPolicy LENIENT
      All coercions allowed. This is the historical behaviour and the default.
    • STRICT

      public static final CoercionPolicy STRICT
      No coercions allowed, values must have the shape of the target type.
  • Method Details

    • coercion

      public static @Nullable CoercionPolicy.Coercion coercion(CoercionPolicy.Target target, CoercionPolicy.Shape shape)
      The coercion needed to read a value of the given shape as the given target type, or null if the shape is the natural one for that target and no coercion is involved.
      Parameters:
      target - The target type
      shape - The shape of the value in the document
      Returns:
      The coercion, or null if none is needed
    • allowedShapes

      public int allowedShapes(CoercionPolicy.Target target)
      The precalculated bit set of CoercionPolicy.Shapes that may be read as the given target type. A decoder should read this once, when it is created, and test it with CoercionPolicy.Shape.bit() for every value it reads.
      Parameters:
      target - The target type
      Returns:
      The bit set of acceptable shapes
    • fromConfiguration

      public static CoercionPolicy fromConfiguration(@Nullable DeserializationConfiguration configuration)
      Resolve the policy from the given configuration.
      Parameters:
      configuration - The deserialization configuration, may be null
      Returns:
      The coercion policy, LENIENT if there is no configuration
    • isAllowed

      public boolean isAllowed(CoercionPolicy.Coercion coercion)
      Parameters:
      coercion - The coercion
      Returns:
      Whether the decoder may perform it
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object