Class SerdeInclusionSourceGen

java.lang.Object
io.micronaut.serde.processor.sourcegen.SerdeInclusionSourceGen

@Internal public final class SerdeInclusionSourceGen extends Object
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 Type
    Method
    Description
    static List<io.micronaut.sourcegen.model.FieldDef>
    The fields holding the resolved inclusion.
    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.
    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.
    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.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.
    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.
    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.
    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.
    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.
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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_DEFAULTS and an absent declaration defer to the runtime configuration and resolve to null. XML nillable properties are always written.
      Parameters:
      element - The serialized type
      property - The property
      keyMetadata - The key metadata contributed with the property
      Returns:
      The inclusion resolved at build time, or null when the configuration decides
    • fields

      public static List<io.micronaut.sourcegen.model.FieldDef> 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 instance
      context - 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 instance
      type - The property type
      propertyValue - 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 only NON_DEFAULT compares the value.
      Parameters:
      aThis - The serializer instance
      include - The inclusion, or null for the runtime configuration
      type - The property type
      propertyValue - The local holding the property value
      Returns:
      The generated condition, or null when 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 instance
      type - The property type
      propertyValue - 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 instance
      include - The inclusion, or null for the runtime configuration
      type - The property type
      propertyValue - The local holding the property value
      Returns:
      The generated condition, or null when 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 instance
      context - The encoder context parameter
      serializer - The property serializer field
      propertyValue - 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 instance
      include - The inclusion, or null for the runtime configuration
      context - The encoder context parameter
      serializer - The property serializer field
      propertyValue - The local holding the property value
      Returns:
      The generated condition, or null when 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, or null
      write - The write statement
      Returns:
      The guarded statement