Class SerdeInclusionSourceGen
java.lang.Object
io.micronaut.serde.processor.sourcegen.SerdeInclusionSourceGen
Generates the inclusion handling shared by the bean and record serializer generators.
The active inclusion is resolved once, in the generated constructor, into two final fields: the
SerdeConfig.SerInclude itself and a flag for a configuration that never skips a property.
A per-property check is then a field read plus, at most, a static call that switches on the already
resolved value.
- Since:
- 3.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<io.micronaut.sourcegen.model.FieldDef> fields()The fields holding the resolved inclusion.static io.micronaut.sourcegen.model.StatementDefguard(@Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef condition, io.micronaut.sourcegen.model.StatementDef write) Wraps a write statement in the inclusion condition, or returns it unchanged when the property is always written.static @Nullable SerdeConfig.SerIncluderesolvePropertyInclude(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.ast.PropertyElement property, Map<String, String> keyMetadata) Resolves the inclusion declared for a property at build time, the way the runtime object serializer resolves it: the property declaration wins over the type, which wins over the package.static List<io.micronaut.sourcegen.model.StatementDef> resolveStatements(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.sourcegen.model.VariableDef.MethodParameter context) The constructor statements resolving the inclusion once per serializer instance.static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializePrimitive(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a primitive property.static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializePrimitive(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a primitive property under an inclusion resolved at build time.static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializeScalar(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a scalar property encoded without a property serializer.static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializeScalar(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a scalar property under an inclusion resolved at build time.static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializeValue(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.sourcegen.model.VariableDef.MethodParameter context, io.micronaut.sourcegen.model.ExpressionDef serializer, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a property through its property serializer under an inclusion resolved at build time.static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDefshouldSerializeValue(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.sourcegen.model.VariableDef.MethodParameter context, io.micronaut.sourcegen.model.ExpressionDef serializer, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a property through its property serializer.
-
Method Details
-
resolvePropertyInclude
public static @Nullable SerdeConfig.SerInclude resolvePropertyInclude(io.micronaut.inject.ast.ClassElement element, io.micronaut.inject.ast.PropertyElement property, Map<String, String> keyMetadata) Resolves the inclusion declared for a property at build time, the way the runtime object serializer resolves it: the property declaration wins over the type, which wins over the package.USE_DEFAULTSand an absent declaration defer to the runtime configuration and resolve tonull. XML nillable properties are always written.- Parameters:
element- The serialized typeproperty- The propertykeyMetadata- The key metadata contributed with the property- Returns:
- The inclusion resolved at build time, or
nullwhen the configuration decides
-
fields
The fields holding the resolved inclusion.- Returns:
- The generated fields
-
resolveStatements
public static List<io.micronaut.sourcegen.model.StatementDef> resolveStatements(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.sourcegen.model.VariableDef.MethodParameter context) The constructor statements resolving the inclusion once per serializer instance.- Parameters:
aThis- The serializer instancecontext- The encoder context constructor parameter- Returns:
- The generated statements
-
shouldSerializePrimitive
public static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializePrimitive(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a primitive property.- Parameters:
aThis- The serializer instancetype- The property typepropertyValue- The local holding the property value- Returns:
- The generated condition
-
shouldSerializePrimitive
public static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializePrimitive(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a primitive property under an inclusion resolved at build time. Primitive values are never null and never empty, so onlyNON_DEFAULTcompares the value.- Parameters:
aThis- The serializer instanceinclude- The inclusion, ornullfor the runtime configurationtype- The property typepropertyValue- The local holding the property value- Returns:
- The generated condition, or
nullwhen the property is always written
-
shouldSerializeScalar
public static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializeScalar(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a scalar property encoded without a property serializer.- Parameters:
aThis- The serializer instancetype- The property typepropertyValue- The local holding the property value- Returns:
- The generated condition
-
shouldSerializeScalar
public static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializeScalar(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.inject.ast.ClassElement type, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a scalar property under an inclusion resolved at build time. The common inclusions compile to a null check; the value-dependent ones call the helper matching the serde that writes the value with the constant inclusion.- Parameters:
aThis- The serializer instanceinclude- The inclusion, ornullfor the runtime configurationtype- The property typepropertyValue- The local holding the property value- Returns:
- The generated condition, or
nullwhen the property is always written
-
shouldSerializeValue
public static io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializeValue(io.micronaut.sourcegen.model.VariableDef.This aThis, io.micronaut.sourcegen.model.VariableDef.MethodParameter context, io.micronaut.sourcegen.model.ExpressionDef serializer, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a property through its property serializer.- Parameters:
aThis- The serializer instancecontext- The encoder context parameterserializer- The property serializer fieldpropertyValue- The local holding the property value- Returns:
- The generated condition
-
shouldSerializeValue
public static @Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef shouldSerializeValue(io.micronaut.sourcegen.model.VariableDef.This aThis, @Nullable SerdeConfig.SerInclude include, io.micronaut.sourcegen.model.VariableDef.MethodParameter context, io.micronaut.sourcegen.model.ExpressionDef serializer, io.micronaut.sourcegen.model.ExpressionDef propertyValue) The condition for writing a property through its property serializer under an inclusion resolved at build time.- Parameters:
aThis- The serializer instanceinclude- The inclusion, ornullfor the runtime configurationcontext- The encoder context parameterserializer- The property serializer fieldpropertyValue- The local holding the property value- Returns:
- The generated condition, or
nullwhen the property is always written
-
guard
public static io.micronaut.sourcegen.model.StatementDef guard(@Nullable io.micronaut.sourcegen.model.ExpressionDef.ConditionExpressionDef condition, io.micronaut.sourcegen.model.StatementDef write) Wraps a write statement in the inclusion condition, or returns it unchanged when the property is always written.- Parameters:
condition- The condition, ornullwrite- The write statement- Returns:
- The guarded statement
-