Class CoercionPolicy
java.lang.Object
io.micronaut.serde.config.CoercionPolicy
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA single coercion a decoder may perform when the JSON shape does not match the requested type.static enumThe shape of a value in the document, as far as coercion is concerned.static enumThe type a decoder is reading a value as. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CoercionPolicyAll coercions allowed.static final CoercionPolicyNo coercions allowed, values must have the shape of the target type. -
Method Summary
Modifier and TypeMethodDescriptionintallowedShapes(CoercionPolicy.Target target) The precalculated bit set ofCoercionPolicy.Shapes that may be read as the given target type.static @Nullable CoercionPolicy.Coercioncoercion(CoercionPolicy.Target target, CoercionPolicy.Shape shape) The coercion needed to read a value of the given shape as the given target type, ornullif the shape is the natural one for that target and no coercion is involved.booleanstatic CoercionPolicyfromConfiguration(@Nullable DeserializationConfiguration configuration) Resolve the policy from the given configuration.inthashCode()booleanisAllowed(CoercionPolicy.Coercion coercion) toString()
-
Field Details
-
LENIENT
All coercions allowed. This is the historical behaviour and the default. -
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, ornullif the shape is the natural one for that target and no coercion is involved.- Parameters:
target- The target typeshape- The shape of the value in the document- Returns:
- The coercion, or
nullif none is needed
-
allowedShapes
The precalculated bit set ofCoercionPolicy.Shapes that may be read as the given target type. A decoder should read this once, when it is created, and test it withCoercionPolicy.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 benull- Returns:
- The coercion policy,
LENIENTif there is no configuration
-
isAllowed
- Parameters:
coercion- The coercion- Returns:
- Whether the decoder may perform it
-
equals
-
hashCode
-
toString
-