Class GeneratedSerdeInclusionUtil
java.lang.Object
io.micronaut.serde.util.GeneratedSerdeInclusionUtil
Inclusion helpers used by generated serializers so that the global
micronaut.serde.serialization.inclusion setting is honored without falling back to the
runtime object serializer for every simple shape.
The active inclusion is resolved once, when a generated serializer is created, and is stored in a generated field. The per-property methods take the already resolved inclusion so that no configuration lookup happens on the serialization hot path.
The scalar methods mirror the isEmpty / isAbsent / isDefault contract of
the runtime serde that would otherwise write the value, so a generated serializer and the runtime
object serializer agree for the same model and configuration.
- Since:
- 3.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanincludeAlways(SerdeConfig.SerInclude include) Whether the resolved inclusion writes every property, which lets generated serializers skip the per-property inclusion check entirely.static SerdeConfig.SerIncludeResolve the inclusion to apply for the given context.static booleanshouldSerialize(SerdeConfig.SerInclude include, Serializer.EncoderContext context, Serializer serializer, @Nullable Object value) Whether a property written by the given serializer should be included.static booleanshouldSerializeBoolean(SerdeConfig.SerInclude include, @Nullable Boolean value) Whether aBooleanproperty should be included.static booleanshouldSerializeCharacter(SerdeConfig.SerInclude include, @Nullable Character value) Whether aCharacterproperty should be included.static booleanshouldSerializeNumber(SerdeConfig.SerInclude include, @Nullable Number value) Whether aNumberproperty should be included.static booleanshouldSerializePrimitive(SerdeConfig.SerInclude include, boolean isDefault) Whether a primitive property should be included.static booleanshouldSerializeString(SerdeConfig.SerInclude include, @Nullable String value) Whether aStringproperty should be included.
-
Method Details
-
resolveInclusion
Resolve the inclusion to apply for the given context. Invoked once per generated serializer instance, never on the per-property path.- Parameters:
context- The encoder context- Returns:
- The active inclusion
-
includeAlways
Whether the resolved inclusion writes every property, which lets generated serializers skip the per-property inclusion check entirely.- Parameters:
include- The resolved inclusion- Returns:
trueif no property can be skipped
-
shouldSerialize
public static boolean shouldSerialize(SerdeConfig.SerInclude include, Serializer.EncoderContext context, Serializer serializer, @Nullable Object value) Whether a property written by the given serializer should be included.- Parameters:
include- The resolved inclusioncontext- The encoder contextserializer- The property serializervalue- The property value- Returns:
trueif the property should be serialized
-
shouldSerializePrimitive
Whether a primitive property should be included. Primitive values are nevernulland never empty, so onlyNEVERandNON_DEFAULTcan skip them.- Parameters:
include- The resolved inclusionisDefault- Whether the value equals the default the matching serde reports for its type- Returns:
trueif the property should be serialized
-
shouldSerializeString
Whether aStringproperty should be included. MirrorsStringSerde, which reportsnulland the empty string as empty and reports no default value.- Parameters:
include- The resolved inclusionvalue- The property value- Returns:
trueif the property should be serialized
-
shouldSerializeNumber
Whether aNumberproperty should be included. Mirrors the number serdes, which report onlynullas empty and treat the boxed zero of their own type as the default value.- Parameters:
include- The resolved inclusionvalue- The property value- Returns:
trueif the property should be serialized
-
shouldSerializeBoolean
public static boolean shouldSerializeBoolean(SerdeConfig.SerInclude include, @Nullable Boolean value) Whether aBooleanproperty should be included. MirrorsBooleanSerde, which treatsfalseas the default value.- Parameters:
include- The resolved inclusionvalue- The property value- Returns:
trueif the property should be serialized
-
shouldSerializeCharacter
public static boolean shouldSerializeCharacter(SerdeConfig.SerInclude include, @Nullable Character value) Whether aCharacterproperty should be included. MirrorsCharSerde, which treats the NUL character as the default value.- Parameters:
include- The resolved inclusionvalue- The property value- Returns:
trueif the property should be serialized
-