Package org.eclipse.yasson.internal
Class AnnotationIntrospector
- java.lang.Object
-
- org.eclipse.yasson.internal.AnnotationIntrospector
-
public class AnnotationIntrospector extends java.lang.ObjectIntrospects configuration on classes and their properties by reading annotations.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>>TRANSIENT_INCOMPATIBLEAnnotations to report exception when used in combination withJsonbTransient.
-
Constructor Summary
Constructors Constructor Description AnnotationIntrospector(JsonbContext jsonbContext)Creates annotation introspecting component passingJsonbContextinside.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckTransientIncompatible(JsonbAnnotatedElement<?> target)Finds annotations incompatible withJsonbTransientannotation.JsonbAnnotatedElement<java.lang.Class<?>>collectAnnotations(java.lang.Class<?> clazz)Collect annotations of given class, its interfaces and the package.java.util.Set<java.lang.Class<?>>collectInterfaces(java.lang.Class<?> cls)Get class interfaces recursively.AdapterBindinggetAdapterBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)Checks forJsonbAdapteron a type.AdapterBindinggetAdapterBinding(Property property)Checks forJsonbAdapteron a property.JsonbDateFormattergetConstructorDateFormatter(JsonbAnnotatedElement<java.lang.reflect.Parameter> param)ReturnsJsonbDateFormatterinstance ifJsonbDateFormatannotation is present.JsonbNumberFormattergetConstructorNumberFormatter(JsonbAnnotatedElement<java.lang.reflect.Parameter> param)ReturnsJsonbNumberFormatterinstance ifJsonbNumberFormatannotation is present.JsonbCreatorgetCreator(java.lang.Class<?> clazz)Searches for JsonbCreator annotation on constructors and static methods.DeserializerBindinggetDeserializerBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)Checks forJsonbDeserializeron a type.DeserializerBindinggetDeserializerBinding(Property property)Checks forJsonbDeserializeron a property.java.lang.Class<?>getImplementationClass(Property property)Returns class ifImplementationClassannotation is present.JsonbDateFormattergetJsonbDateFormat(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)Search forJsonbDateFormatannotation on java class and constructJsonbDateFormatter.java.util.Map<AnnotationTarget,JsonbDateFormatter>getJsonbDateFormatCategorized(Property property)SearchJsonbDateFormaton property, if not found looks at annotations declared on property type class.JsonbNumberFormattergetJsonbNumberFormat(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)Search forJsonbNumberFormatannotation on java class.java.lang.StringgetJsonbPropertyJsonReadName(Property property)Gets a name of property for JSON unmarshalling.java.lang.StringgetJsonbPropertyJsonWriteName(Property property)Gets a name of property for JSON marshalling.java.util.EnumSet<AnnotationTarget>getJsonbTransientCategorized(Property property)Checks if property is annotated transient.java.util.Map<AnnotationTarget,JsonbNumberFormatter>getJsonNumberFormatter(Property property)SearchJsonbNumberFormaton property, if not found looks at annotations declared on property type class.java.lang.String[]getPropertyOrder(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)Checks forJsonbPropertyOrderannotation.javax.json.bind.config.PropertyVisibilityStrategygetPropertyVisibilityStrategy(java.lang.Class<?> clazz)Get a @JsonbVisibility annotation from a class or its package.SerializerBindinggetSerializerBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)Checks forJsonbSerializeron a type.SerializerBindinggetSerializerBinding(Property property)Checks forJsonbSerializeron a property.ClassCustomizationintrospectCustomization(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)Processes customizations.booleanisClassNillable(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)Checks for JsonbNillable annotation on a class, its superclasses and interfaces.java.util.Optional<java.lang.Boolean>isPropertyNillable(Property property)Checks if property is nillable.
-
-
-
Constructor Detail
-
AnnotationIntrospector
public AnnotationIntrospector(JsonbContext jsonbContext)
Creates annotation introspecting component passingJsonbContextinside.- Parameters:
jsonbContext- mandatory
-
-
Method Detail
-
getJsonbPropertyJsonWriteName
public java.lang.String getJsonbPropertyJsonWriteName(Property property)
Gets a name of property for JSON marshalling. Can be different writeName for same property.- Parameters:
property- property representation - field, getter, setter (not null)- Returns:
- read name
-
getJsonbPropertyJsonReadName
public java.lang.String getJsonbPropertyJsonReadName(Property property)
Gets a name of property for JSON unmarshalling. Can be different from writeName for same property.- Parameters:
property- property representation - field, getter, setter (not null)- Returns:
- write name
-
getCreator
public JsonbCreator getCreator(java.lang.Class<?> clazz)
Searches for JsonbCreator annotation on constructors and static methods.- Parameters:
clazz- class to search- Returns:
- JsonbCreator metadata object
-
getAdapterBinding
public AdapterBinding getAdapterBinding(Property property)
Checks forJsonbAdapteron a property.- Parameters:
property- property not null- Returns:
- components info
-
getAdapterBinding
public AdapterBinding getAdapterBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)
Checks forJsonbAdapteron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
getDeserializerBinding
public DeserializerBinding getDeserializerBinding(Property property)
Checks forJsonbDeserializeron a property.- Parameters:
property- property not null- Returns:
- components info
-
getDeserializerBinding
public DeserializerBinding getDeserializerBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)
Checks forJsonbDeserializeron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
getSerializerBinding
public SerializerBinding getSerializerBinding(Property property)
Checks forJsonbSerializeron a property.- Parameters:
property- property not null- Returns:
- components info
-
getSerializerBinding
public SerializerBinding getSerializerBinding(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)
Checks forJsonbSerializeron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
isPropertyNillable
public java.util.Optional<java.lang.Boolean> isPropertyNillable(Property property)
Checks if property is nillable. Looks forJsonbPropertynillable attribute only. JsonbNillable is checked only for ClassModels.- Parameters:
property- property to search in, not null- Returns:
- True if property should be serialized when null.
-
isClassNillable
public boolean isClassNillable(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)
Checks for JsonbNillable annotation on a class, its superclasses and interfaces.- Parameters:
clazzElement- class to search JsonbNillable in.- Returns:
- true if found
-
getPropertyOrder
public java.lang.String[] getPropertyOrder(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)
Checks forJsonbPropertyOrderannotation.- Parameters:
clazzElement- class to search on- Returns:
- ordered properties names or null if not found
-
getJsonbTransientCategorized
public java.util.EnumSet<AnnotationTarget> getJsonbTransientCategorized(Property property)
Checks if property is annotated transient. If JsonbTransient annotation is present on field getter or setter, and other annotation is present on either of it, JsonbException is thrown with message describing collision.- Parameters:
property- The property to inspect if there is anyJsonbTransientannotation defined for it- Returns:
- Set of
AnnotationTargets specifying in which scope theJsonbTransientis applied
-
getJsonbDateFormatCategorized
public java.util.Map<AnnotationTarget,JsonbDateFormatter> getJsonbDateFormatCategorized(Property property)
SearchJsonbDateFormaton property, if not found looks at annotations declared on property type class.- Parameters:
property- Property to search on.- Returns:
- Map of
JsonbDateFormatterinstances categorized by their scopes (class, property, getter or setter). If there is no date formatter specified for given property, an empty map would be returned
-
getJsonbDateFormat
public JsonbDateFormatter getJsonbDateFormat(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)
Search forJsonbDateFormatannotation on java class and constructJsonbDateFormatter. If not found looks at annotations declared on property type class.- Parameters:
clazzElement- class to search not null- Returns:
- formatter to use
-
getJsonbNumberFormat
public JsonbNumberFormatter getJsonbNumberFormat(JsonbAnnotatedElement<java.lang.Class<?>> clazzElement)
Search forJsonbNumberFormatannotation on java class.- Parameters:
clazzElement- class to search not null- Returns:
- formatter to use
-
getJsonNumberFormatter
public java.util.Map<AnnotationTarget,JsonbNumberFormatter> getJsonNumberFormatter(Property property)
SearchJsonbNumberFormaton property, if not found looks at annotations declared on property type class.- Parameters:
property- Property to search on.- Returns:
- Map of
JsonbNumberFormatterinstances categorized by their scopes (class, property, getter or setter). If there is no number formatter specified for given property, an empty map would be returned
-
getConstructorNumberFormatter
public JsonbNumberFormatter getConstructorNumberFormatter(JsonbAnnotatedElement<java.lang.reflect.Parameter> param)
ReturnsJsonbNumberFormatterinstance ifJsonbNumberFormatannotation is present.- Parameters:
param- annotated method parameter- Returns:
- formatter instance if
JsonbNumberFormatis present otherwise null
-
getConstructorDateFormatter
public JsonbDateFormatter getConstructorDateFormatter(JsonbAnnotatedElement<java.lang.reflect.Parameter> param)
ReturnsJsonbDateFormatterinstance ifJsonbDateFormatannotation is present.- Parameters:
param- annotated method parameter- Returns:
- formatter instance if
JsonbDateFormatis present otherwise null
-
getPropertyVisibilityStrategy
public javax.json.bind.config.PropertyVisibilityStrategy getPropertyVisibilityStrategy(java.lang.Class<?> clazz)
Get a @JsonbVisibility annotation from a class or its package.- Parameters:
clazz- Class to lookup annotation- Returns:
- Instantiated PropertyVisibilityStrategy if annotation is present
-
checkTransientIncompatible
public void checkTransientIncompatible(JsonbAnnotatedElement<?> target)
Finds annotations incompatible withJsonbTransientannotation.- Parameters:
target- target to check
-
collectInterfaces
public java.util.Set<java.lang.Class<?>> collectInterfaces(java.lang.Class<?> cls)
Get class interfaces recursively.- Parameters:
cls- Class to process.- Returns:
- A list of all class interfaces.
-
introspectCustomization
public ClassCustomization introspectCustomization(JsonbAnnotatedElement<java.lang.Class<?>> clsElement)
Processes customizations.- Parameters:
clsElement- Element to process.- Returns:
- Populated
ClassCustomizationinstance.
-
getImplementationClass
public java.lang.Class<?> getImplementationClass(Property property)
Returns class ifImplementationClassannotation is present.- Parameters:
property- annotated property- Returns:
- Class if
ImplementationClassis present otherwise null
-
collectAnnotations
public JsonbAnnotatedElement<java.lang.Class<?>> collectAnnotations(java.lang.Class<?> clazz)
Collect annotations of given class, its interfaces and the package.- Parameters:
clazz- Class to process.- Returns:
- Element with class and annotations.
-
-