Class CompositeAnnotator

java.lang.Object
org.jsonschema2pojo.CompositeAnnotator
All Implemented Interfaces:
Annotator

public class CompositeAnnotator extends Object implements Annotator
An annotator (implementing the composite pattern) that can be used to compose many annotators together.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new composite annotator, made up of a given set of child annotators.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    additionalPropertiesField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, String propertyName)
    Add the necessary annotations to the field that will hold 'additional' properties.
    void
    anyGetter(com.sun.codemodel.JMethod getter, com.sun.codemodel.JDefinedClass clazz)
    Add the necessary annotation to mark a Java method as the getter for additional JSON property values that do not match any of the other property names found in the bean.
    void
    anySetter(com.sun.codemodel.JMethod setter, com.sun.codemodel.JDefinedClass clazz)
    Add the necessary annotation to mark a Java method as the setter for additional JSON property values that do not match any of the other property names found in the bean.
    void
    dateField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
    Add the necessary annotations to a date field.
    void
    dateTimeField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
    Add the necessary annotations to a date-time field.
    void
    enumConstant(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JEnumConstant constant, String value)
    Add the necessary annotations to an enum constant.
    void
    enumCreatorMethod(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JMethod creatorMethod)
    Add the necessary annotation to mark a static Java method as the creator/factory method which can choose the correct Java enum value for a given JSON value during deserialization.
    void
    enumValueMethod(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JMethod valueMethod)
    Add the necessary annotation to mark a Java method as the value method that is used to turn a Java enum value into a JSON value during serialization.
    boolean
    Indicates whether the annotation style that this annotator uses can support the JSON Schema 'additionalProperties' feature.
    boolean
    isPolymorphicDeserializationSupported(com.fasterxml.jackson.databind.JsonNode node)
    Indicates whether type hint annotations should be added to support polymorphic deserialization.
    void
    propertyField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, String propertyName, com.fasterxml.jackson.databind.JsonNode propertyNode)
    Add the necessary annotation to mark a Java field as a JSON property
    void
    propertyGetter(com.sun.codemodel.JMethod getter, com.sun.codemodel.JDefinedClass clazz, String propertyName)
    Add the necessary annotation to mark a Java method as the getter for a JSON property
    void
    propertyInclusion(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode schema)
    Add the necessary annotation to cause only non-null values to be included during serialization.
    void
    propertyOrder(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertiesNode)
    Add the necessary annotation to dictate correct property order during serialization
    void
    propertySetter(com.sun.codemodel.JMethod setter, com.sun.codemodel.JDefinedClass clazz, String propertyName)
    Add the necessary annotation to mark a Java method as the setter for a JSON property
    void
    timeField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
    Add the necessary annotations to a time field.
    void
    typeInfo(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode node)
    Add the necessary annotation to dictate correct type information during serialization and deserialization; often required with polymorphic types.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CompositeAnnotator

      public CompositeAnnotator(Annotator... annotators)
      Create a new composite annotator, made up of a given set of child annotators.
      Parameters:
      annotators - The annotators that will be called whenever this annotator is called. The child annotators provided will called in the order that they appear in this argument list.
  • Method Details

    • typeInfo

      public void typeInfo(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode node)
      Description copied from interface: Annotator
      Add the necessary annotation to dictate correct type information during serialization and deserialization; often required with polymorphic types.
      Specified by:
      typeInfo in interface Annotator
      Parameters:
      clazz - a generated pojo class, that needs serialization annotations
      node - the object schema associated with this clazz
      See Also:
    • propertyOrder

      public void propertyOrder(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertiesNode)
      Description copied from interface: Annotator
      Add the necessary annotation to dictate correct property order during serialization
      Specified by:
      propertyOrder in interface Annotator
      Parameters:
      clazz - a generated pojo class, that needs serialization annotations
      propertiesNode - the properties to be ordered
    • propertyInclusion

      public void propertyInclusion(com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode schema)
      Description copied from interface: Annotator
      Add the necessary annotation to cause only non-null values to be included during serialization.
      Specified by:
      propertyInclusion in interface Annotator
      Parameters:
      clazz - a generated pojo class, that needs serialization annotations
      schema - the object schema associated with this clazz
    • propertyField

      public void propertyField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, String propertyName, com.fasterxml.jackson.databind.JsonNode propertyNode)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java field as a JSON property
      Specified by:
      propertyField in interface Annotator
      Parameters:
      field - the field that contains data that will be serialized
      clazz - a generated pojo class, that needs serialization annotations
      propertyName - the name of the JSON property that this field represents
      propertyNode - the schema node defining this property
    • propertyGetter

      public void propertyGetter(com.sun.codemodel.JMethod getter, com.sun.codemodel.JDefinedClass clazz, String propertyName)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java method as the getter for a JSON property
      Specified by:
      propertyGetter in interface Annotator
      Parameters:
      getter - the method that will be used to get the value of the given JSON property
      clazz - a generated pojo class, that needs serialization annotations
      propertyName - the name of the JSON property that this getter gets
    • propertySetter

      public void propertySetter(com.sun.codemodel.JMethod setter, com.sun.codemodel.JDefinedClass clazz, String propertyName)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java method as the setter for a JSON property
      Specified by:
      propertySetter in interface Annotator
      Parameters:
      setter - the method that will be used to set the value of the given JSON property
      clazz - a generated pojo class, that needs serialization annotations
      propertyName - the name of the JSON property that this setter sets
    • anyGetter

      public void anyGetter(com.sun.codemodel.JMethod getter, com.sun.codemodel.JDefinedClass clazz)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java method as the getter for additional JSON property values that do not match any of the other property names found in the bean.
      Specified by:
      anyGetter in interface Annotator
      Parameters:
      getter - the method that will be used to get the values of additional properties
      clazz - a generated pojo class, that needs serialization annotations
    • anySetter

      public void anySetter(com.sun.codemodel.JMethod setter, com.sun.codemodel.JDefinedClass clazz)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java method as the setter for additional JSON property values that do not match any of the other property names found in the bean.
      Specified by:
      anySetter in interface Annotator
      Parameters:
      setter - the method that will be used to set the values of additional properties
      clazz - a generated pojo class, that needs serialization annotations
    • enumCreatorMethod

      public void enumCreatorMethod(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JMethod creatorMethod)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a static Java method as the creator/factory method which can choose the correct Java enum value for a given JSON value during deserialization.
      Specified by:
      enumCreatorMethod in interface Annotator
      Parameters:
      _enum - a generated enum class, that needs serialization annotations
      creatorMethod - the method that can create a Java enum value from a JSON value
    • enumValueMethod

      public void enumValueMethod(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JMethod valueMethod)
      Description copied from interface: Annotator
      Add the necessary annotation to mark a Java method as the value method that is used to turn a Java enum value into a JSON value during serialization.
      Specified by:
      enumValueMethod in interface Annotator
      Parameters:
      _enum - a generated enum class, that needs serialization annotations
      valueMethod - the enum instance method that can create a JSON value during serialization
    • enumConstant

      public void enumConstant(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JEnumConstant constant, String value)
      Description copied from interface: Annotator
      Add the necessary annotations to an enum constant. For instance, to force the given value to be used when serializing.
      Specified by:
      enumConstant in interface Annotator
      Parameters:
      _enum - a generated enum class, that needs serialization annotations
      constant - one of the constants within _enum
      value - the value to use when serializing this constant
    • isAdditionalPropertiesSupported

      public boolean isAdditionalPropertiesSupported()
      Description copied from interface: Annotator
      Indicates whether the annotation style that this annotator uses can support the JSON Schema 'additionalProperties' feature. In other words, can the deserializer associated with this annotation style gather unexpected, additional json properties and does it expect to include them somewhere in the target Java instance.

      Jackson is able to use it's JsonAnyGetter and JsonAnySetter features for this purpose, hence for Jackson annotators, this method will return true. Gson does not support 'additional' property values (they are silently discarded at deserialization time), hence for Gson annotators, this method would return false. Moshi 1.x behaves similar to Gson and therefore returns false.

      Specified by:
      isAdditionalPropertiesSupported in interface Annotator
      Returns:
      Whether this annotator has any way to support 'additional properties'.
    • additionalPropertiesField

      public void additionalPropertiesField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, String propertyName)
      Description copied from interface: Annotator
      Add the necessary annotations to the field that will hold 'additional' properties.
      Specified by:
      additionalPropertiesField in interface Annotator
      Parameters:
      field - the field (usually a Map) that will hold properties that are not explicitly mentioned in the schema
      clazz - a generated pojo class, that needs serialization annotations
      propertyName - unused
    • isPolymorphicDeserializationSupported

      public boolean isPolymorphicDeserializationSupported(com.fasterxml.jackson.databind.JsonNode node)
      Description copied from interface: Annotator
      Indicates whether type hint annotations should be added to support polymorphic deserialization.
      Specified by:
      isPolymorphicDeserializationSupported in interface Annotator
      Parameters:
      node - the relevant schema node
      Returns:
      true if the JSON library supports polymorphic deserialization AND the deserializationClassProperty is present in this schema
    • dateTimeField

      public void dateTimeField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
      Description copied from interface: Annotator
      Add the necessary annotations to a date-time field. For instance, to format the date-time in the expected style.
      Specified by:
      dateTimeField in interface Annotator
      Parameters:
      field - the field that contains data that will be serialized
      clazz - a generated pojo class, that needs serialization annotations
      propertyNode - the schema node defining this property
    • dateField

      public void dateField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
      Description copied from interface: Annotator
      Add the necessary annotations to a date field. For instance, to format the date in the expected style.
      Specified by:
      dateField in interface Annotator
      Parameters:
      field - the field that contains data that will be serialized
      clazz - a generated pojo class, that needs serialization annotations
      propertyNode - the schema node defining this property
    • timeField

      public void timeField(com.sun.codemodel.JFieldVar field, com.sun.codemodel.JDefinedClass clazz, com.fasterxml.jackson.databind.JsonNode propertyNode)
      Description copied from interface: Annotator
      Add the necessary annotations to a time field. For instance, to format the time in the expected style.
      Specified by:
      timeField in interface Annotator
      Parameters:
      field - the field that contains data that will be serialized
      clazz - a generated pojo class, that needs serialization annotations
      propertyNode - the schema node defining this property