Class Moshi1Annotator

java.lang.Object
org.jsonschema2pojo.AbstractAnnotator
org.jsonschema2pojo.Moshi1Annotator
All Implemented Interfaces:
Annotator

public class Moshi1Annotator extends AbstractAnnotator
Annotates generated Java types using Moshi. The annotations used here are most useful when the JSON fields have characters (like underscores) that are poorly suited for beans. By using the Moshi 'Json' annotation, we are able to preserve the original format.
See Also:
  • Constructor Details

  • Method Details

    • 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
      Overrides:
      propertyField in class AbstractAnnotator
      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
    • 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
      Overrides:
      enumConstant in class AbstractAnnotator
      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
      Overrides:
      isAdditionalPropertiesSupported in class AbstractAnnotator
      Returns:
      Whether this annotator has any way to support 'additional properties'.