Class AnnotationIntrospector
java.lang.Object
org.eclipse.yasson.internal.AnnotationIntrospector
Introspects configuration on classes and their properties by reading annotations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ConstructorPropertiesAnnotationIntrospectorprivate final JsonbContextprivate static final Set<Class<? extends Annotation>> private static final List<Class<? extends Annotation>> Annotations to report exception when used in combination withJsonbTransient. -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationIntrospector(JsonbContext jsonbContext) Creates annotation introspecting component passingJsonbContextinside. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddIfNotPresent(JsonbAnnotatedElement<?> element, Class<?> definedType, Annotation... annotations) private voidcheckDuplicityPolymorphicPropertyNames(TypeInheritanceConfiguration typeInheritanceConfiguration) voidcheckTransientIncompatible(JsonbAnnotatedElement<?> target) Finds annotations incompatible withJsonbTransientannotation.collectAnnotations(Class<?> clazz) Collect annotations of given class, its interfaces and the package.private <T extends Annotation>
voidcollectFromInterfaces(Class<T> annotationClass, Class<?> clazz, Map<Class<?>, T> collectedAnnotations) private Map<Class<? extends Annotation>, LinkedList<JsonbAnnotatedElement.AnnotationWrapper<?>>> collectInterfaceAnnotations(Class<?> currentInterf, Class<?> processed) collectInterfaces(Class<?> cls) Get class interfaces recursively.(package private) JsonbCreatorcreateJsonbCreator(Executable executable, JsonbCreator existing, Class<?> clazz, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) private JsonbDateFormattercreateJsonbDateFormatter(String format, String locale, Property property) CreatesJsonbDateFormattercaches formatter instance if possible.private <T extends Annotation>
TfindAnnotation(Annotation[] declaredAnnotations, Class<T> annotationClass) getAdapterBinding(Parameter parameter) Checks forJsonbAdapteron aParameter.getAdapterBinding(JsonbAnnotatedElement<Class<?>> clsElement) Checks forJsonbAdapteron a type.getAdapterBinding(Property property) Checks forJsonbAdapteron a property.private AdapterBindinggetAdapterBindingFromAnnotation(jakarta.json.bind.annotation.JsonbTypeAdapter adapterAnnotation, Optional<Class<?>> expectedClass) private <T extends Annotation>
TgetAnnotationFromParameterType(Parameter parameter, Class<T> annotationClass) private <T extends Annotation>
Optional<T> getAnnotationFromProperty(Class<T> annotationClass, Property property) Gets an annotation from first resolved annotation in a property in this order:private <T extends Annotation>
Map<AnnotationTarget, T> getAnnotationFromPropertyCategorized(Class<T> annotationClass, Property property) An override ofgetAnnotationFromProperty(Class, Property)in which it returns the results as a map so that the caller can decide which one to be used for read/write operation.private <T extends Annotation>
TgetAnnotationFromPropertyType(Property property, Class<T> annotationClass) ReturnsJsonbDateFormatterinstance ifJsonbDateFormatannotation is present.ReturnsJsonbNumberFormatterinstance ifJsonbNumberFormatannotation is present.getCreator(Class<?> clazz, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) Searches for JsonbCreator annotation on constructors and static methods.getDeserializerBinding(Parameter parameter) Checks forJsonbDeserializeron aParameter.getDeserializerBinding(JsonbAnnotatedElement<Class<?>> clsElement) Checks forJsonbDeserializeron a type.getDeserializerBinding(Property property) Checks forJsonbDeserializeron a property.private <T extends Annotation>
TgetFieldAnnotation(Class<T> annotationClass, JsonbAnnotatedElement<Field> fieldElement) Class<?> getImplementationClass(Property property) Returns class ifImplementationClassannotation is present.getJsonbDateFormat(JsonbAnnotatedElement<Class<?>> clazzElement) Search forJsonbDateFormatannotation on java class and constructJsonbDateFormatter.getJsonbDateFormatCategorized(Property property) SearchJsonbDateFormaton property, if not found looks at annotations declared on property type class.getJsonbNumberFormat(JsonbAnnotatedElement<Class<?>> clazzElement) Search forJsonbNumberFormatannotation on java class.private StringgetJsonbPropertyCustomizedName(Property property, JsonbAnnotatedElement<Method> methodElement) getJsonbPropertyJsonReadName(Property property) Gets a name of property for JSON unmarshalling.getJsonbPropertyJsonWriteName(Property property) Gets a name of property for JSON marshalling.getJsonbTransientCategorized(Property property) Checks if property is annotated transient.getJsonNumberFormatter(Property property) SearchJsonbNumberFormaton property, if not found looks at annotations declared on property type class.private <T extends Annotation>
TgetMethodAnnotation(Class<T> annotationClass, JsonbAnnotatedElement<Method> methodElement) private TypeInheritanceConfigurationgetPolymorphismConfig(JsonbAnnotatedElement<Class<?>> clsElement, ClassCustomization parentCustomization) String[]getPropertyOrder(JsonbAnnotatedElement<Class<?>> clazzElement) Checks forJsonbPropertyOrderannotation.jakarta.json.bind.config.PropertyVisibilityStrategygetPropertyVisibilityStrategy(Class<?> clazz) Get a @JsonbVisibility annotation from a class or its package.getSerializerBinding(JsonbAnnotatedElement<Class<?>> clsElement) Checks forJsonbSerializeron a type.getSerializerBinding(Property property) Checks forJsonbSerializeron a property.introspectCustomization(JsonbAnnotatedElement<Class<?>> clsElement, ClassCustomization parentCustomization, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) Processes customizations.booleanisClassNillable(JsonbAnnotatedElement<Class<?>> clazzElement) Checks for JsonbNillable annotation on a class, its superclasses and interfaces.isPropertyNillable(Property property) Checks if property is nillable.booleanrequiredParameters(Executable executable, JsonbAnnotatedElement<Parameter> annotated)
-
Field Details
-
jsonbContext
-
constructorPropertiesIntrospector
-
REPEATABLE
-
TRANSIENT_INCOMPATIBLE
Annotations to report exception when used in combination withJsonbTransient.
-
-
Constructor Details
-
AnnotationIntrospector
Creates annotation introspecting component passingJsonbContextinside.- Parameters:
jsonbContext- mandatory
-
-
Method Details
-
getJsonbPropertyJsonWriteName
-
getJsonbPropertyJsonReadName
-
getJsonbPropertyCustomizedName
private String getJsonbPropertyCustomizedName(Property property, JsonbAnnotatedElement<Method> methodElement) -
getCreator
public JsonbCreator getCreator(Class<?> clazz, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) Searches for JsonbCreator annotation on constructors and static methods.- Parameters:
clazz- class to searchpropertyNamingStrategy- The naming strategy to use for the $JsonbConstructorannotation, if set and noJsonbPropertyannotations are present.- Returns:
- JsonbCreator metadata object
-
createJsonbCreator
JsonbCreator createJsonbCreator(Executable executable, JsonbCreator existing, Class<?> clazz, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) -
getAdapterBinding
Checks forJsonbAdapteron a property.- Parameters:
property- property not null- Returns:
- components info
-
getAdapterBinding
Checks forJsonbAdapteron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
getAdapterBindingFromAnnotation
private AdapterBinding getAdapterBindingFromAnnotation(jakarta.json.bind.annotation.JsonbTypeAdapter adapterAnnotation, Optional<Class<?>> expectedClass) -
getDeserializerBinding
Checks forJsonbDeserializeron a property.- Parameters:
property- property not null- Returns:
- components info
-
getDeserializerBinding
Checks forJsonbDeserializeron aParameter.- Parameters:
parameter- parameter not null- Returns:
- components info
-
getAdapterBinding
Checks forJsonbAdapteron aParameter.- Parameters:
parameter- parameter not null- Returns:
- components info
-
getAnnotationFromParameterType
private <T extends Annotation> T getAnnotationFromParameterType(Parameter parameter, Class<T> annotationClass) -
getDeserializerBinding
Checks forJsonbDeserializeron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
getSerializerBinding
Checks forJsonbSerializeron a property.- Parameters:
property- property not null- Returns:
- components info
-
getSerializerBinding
Checks forJsonbSerializeron a type.- Parameters:
clsElement- type not null- Returns:
- components info
-
getAnnotationFromPropertyType
private <T extends Annotation> T getAnnotationFromPropertyType(Property property, Class<T> annotationClass) -
isPropertyNillable
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
Checks for JsonbNillable annotation on a class, its superclasses and interfaces.- Parameters:
clazzElement- class to search JsonbNillable in.- Returns:
- true if found
-
getPropertyOrder
Checks forJsonbPropertyOrderannotation.- Parameters:
clazzElement- class to search on- Returns:
- ordered properties names or null if not found
-
getJsonbTransientCategorized
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
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
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
Search forJsonbNumberFormatannotation on java class.- Parameters:
clazzElement- class to search not null- Returns:
- formatter to use
-
getJsonNumberFormatter
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
ReturnsJsonbNumberFormatterinstance ifJsonbNumberFormatannotation is present.- Parameters:
param- annotated method parameter- Returns:
- formatter instance if
JsonbNumberFormatis present otherwise null
-
getConstructorDateFormatter
ReturnsJsonbDateFormatterinstance ifJsonbDateFormatannotation is present.- Parameters:
param- annotated method parameter- Returns:
- formatter instance if
JsonbDateFormatis present otherwise null
-
createJsonbDateFormatter
private JsonbDateFormatter createJsonbDateFormatter(String format, String locale, Property property) CreatesJsonbDateFormattercaches formatter instance if possible. For DEFAULT_FORMAT appropriate singleton instances from java.time.format.DateTimeFormatter are used in date converters. -
getPropertyVisibilityStrategy
public jakarta.json.bind.config.PropertyVisibilityStrategy getPropertyVisibilityStrategy(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
-
getAnnotationFromProperty
private <T extends Annotation> Optional<T> getAnnotationFromProperty(Class<T> annotationClass, Property property) Gets an annotation from first resolved annotation in a property in this order:1. Field, 2. Getter, 3 Setter.
First found overrides other.- Type Parameters:
T- Annotation type- Parameters:
annotationClass- Annotation class to search forproperty- property to search in- Returns:
- Annotation if found, null otherwise
-
getAnnotationFromPropertyCategorized
private <T extends Annotation> Map<AnnotationTarget, T> getAnnotationFromPropertyCategorized(Class<T> annotationClass, Property property) An override ofgetAnnotationFromProperty(Class, Property)in which it returns the results as a map so that the caller can decide which one to be used for read/write operation. Some annotations should have different behaviours based on the scope that they're applied on.- Type Parameters:
T- Annotation type- Parameters:
annotationClass- The annotation class to searchproperty- The property to search in- Returns:
- A map of all occurrences of requested annotation for given property. Caller can determine based on
AnnotationTargetthat given annotation is specified on what level (Class, Property, Getter or Setter). If no annotation found for given property, an empty map would be returned
-
getFieldAnnotation
private <T extends Annotation> T getFieldAnnotation(Class<T> annotationClass, JsonbAnnotatedElement<Field> fieldElement) -
findAnnotation
private <T extends Annotation> T findAnnotation(Annotation[] declaredAnnotations, Class<T> annotationClass) -
checkTransientIncompatible
Finds annotations incompatible withJsonbTransientannotation.- Parameters:
target- target to check
-
getMethodAnnotation
private <T extends Annotation> T getMethodAnnotation(Class<T> annotationClass, JsonbAnnotatedElement<Method> methodElement) -
collectFromInterfaces
private <T extends Annotation> void collectFromInterfaces(Class<T> annotationClass, Class<?> clazz, Map<Class<?>, T> collectedAnnotations) -
collectInterfaces
-
introspectCustomization
public ClassCustomization introspectCustomization(JsonbAnnotatedElement<Class<?>> clsElement, ClassCustomization parentCustomization, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy) Processes customizations.- Parameters:
clsElement- Element to process.propertyNamingStrategy- The naming strategy to use for the $JsonbConstructorannotation, if set and noJsonbPropertyannotations are present.- Returns:
- Populated
ClassCustomizationinstance.
-
getPolymorphismConfig
private TypeInheritanceConfiguration getPolymorphismConfig(JsonbAnnotatedElement<Class<?>> clsElement, ClassCustomization parentCustomization) -
checkDuplicityPolymorphicPropertyNames
private void checkDuplicityPolymorphicPropertyNames(TypeInheritanceConfiguration typeInheritanceConfiguration) -
getImplementationClass
Returns class ifImplementationClassannotation is present.- Parameters:
property- annotated property- Returns:
- Class if
ImplementationClassis present otherwise null
-
collectAnnotations
Collect annotations of given class, its interfaces and the package.- Parameters:
clazz- Class to process.- Returns:
- Element with class and annotations.
-
collectInterfaceAnnotations
private Map<Class<? extends Annotation>, LinkedList<JsonbAnnotatedElement.AnnotationWrapper<?>>> collectInterfaceAnnotations(Class<?> currentInterf, Class<?> processed) -
addIfNotPresent
private void addIfNotPresent(JsonbAnnotatedElement<?> element, Class<?> definedType, Annotation... annotations) -
requiredParameters
public boolean requiredParameters(Executable executable, JsonbAnnotatedElement<Parameter> annotated)
-