Package org.jsonschema2pojo
Class GsonAnnotator
java.lang.Object
org.jsonschema2pojo.AbstractAnnotator
org.jsonschema2pojo.GsonAnnotator
- All Implemented Interfaces:
Annotator
Annotates generated Java types using Gson. The annotations used here are most
useful when the JSON fields have characters (like underscores) that are
poorly suited for beans. By using the
SerializedName annotation, we
are able to preserve the original format. Use this in conjunction with
GenerationConfig.getPropertyWordDelimiters() to filter out underscores
or other unwanted delimiters but still marshal/unmarshal the same content.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidenumConstant(com.sun.codemodel.JDefinedClass _enum, com.sun.codemodel.JEnumConstant constant, String value) Add the necessary annotations to an enum constant.booleanIndicates whether the annotation style that this annotator uses can support the JSON Schema 'additionalProperties' feature.voidpropertyField(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 propertyMethods inherited from class org.jsonschema2pojo.AbstractAnnotator
additionalPropertiesField, anyGetter, anySetter, dateField, dateTimeField, enumCreatorMethod, enumValueMethod, getGenerationConfig, isPolymorphicDeserializationSupported, propertyGetter, propertyInclusion, propertyOrder, propertySetter, timeField, typeInfo
-
Constructor Details
-
GsonAnnotator
-
-
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:AnnotatorAdd the necessary annotation to mark a Java field as a JSON property- Specified by:
propertyFieldin interfaceAnnotator- Overrides:
propertyFieldin classAbstractAnnotator- Parameters:
field- the field that contains data that will be serializedclazz- a generated pojo class, that needs serialization annotationspropertyName- the name of the JSON property that this field representspropertyNode- 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:AnnotatorAdd the necessary annotations to an enum constant. For instance, to force the given value to be used when serializing.- Specified by:
enumConstantin interfaceAnnotator- Overrides:
enumConstantin classAbstractAnnotator- Parameters:
_enum- a generated enum class, that needs serialization annotationsconstant- one of the constants within _enumvalue- the value to use when serializing this constant
-
isAdditionalPropertiesSupported
public boolean isAdditionalPropertiesSupported()Description copied from interface:AnnotatorIndicates 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
JsonAnyGetterandJsonAnySetterfeatures for this purpose, hence for Jackson annotators, this method will returntrue. Gson does not support 'additional' property values (they are silently discarded at deserialization time), hence for Gson annotators, this method would returnfalse. Moshi 1.x behaves similar to Gson and therefore returnsfalse.- Specified by:
isAdditionalPropertiesSupportedin interfaceAnnotator- Overrides:
isAdditionalPropertiesSupportedin classAbstractAnnotator- Returns:
- Whether this annotator has any way to support 'additional properties'.
-