Class AnnotationIntrospector

java.lang.Object
org.eclipse.yasson.internal.AnnotationIntrospector

public class AnnotationIntrospector extends Object
Introspects configuration on classes and their properties by reading annotations.
  • Field Details

  • Constructor Details

    • AnnotationIntrospector

      public AnnotationIntrospector(JsonbContext jsonbContext)
      Creates annotation introspecting component passing JsonbContext inside.
      Parameters:
      jsonbContext - mandatory
  • Method Details

    • getJsonbPropertyJsonWriteName

      public 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 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
    • 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 search
      propertyNamingStrategy - The naming strategy to use for the $JsonbConstructor annotation, if set and no JsonbProperty annotations are present.
      Returns:
      JsonbCreator metadata object
    • createJsonbCreator

      JsonbCreator createJsonbCreator(Executable executable, JsonbCreator existing, Class<?> clazz, jakarta.json.bind.config.PropertyNamingStrategy propertyNamingStrategy)
    • getAdapterBinding

      public AdapterBinding getAdapterBinding(Property property)
      Checks for JsonbAdapter on a property.
      Parameters:
      property - property not null
      Returns:
      components info
    • getAdapterBinding

      public AdapterBinding getAdapterBinding(JsonbAnnotatedElement<Class<?>> clsElement)
      Checks for JsonbAdapter on a type.
      Parameters:
      clsElement - type not null
      Returns:
      components info
    • getAdapterBindingFromAnnotation

      private AdapterBinding getAdapterBindingFromAnnotation(jakarta.json.bind.annotation.JsonbTypeAdapter adapterAnnotation, Optional<Class<?>> expectedClass)
    • getDeserializerBinding

      public DeserializerBinding getDeserializerBinding(Property property)
      Checks for JsonbDeserializer on a property.
      Parameters:
      property - property not null
      Returns:
      components info
    • getDeserializerBinding

      public DeserializerBinding<?> getDeserializerBinding(Parameter parameter)
      Checks for JsonbDeserializer on a Parameter.
      Parameters:
      parameter - parameter not null
      Returns:
      components info
    • getAdapterBinding

      public AdapterBinding getAdapterBinding(Parameter parameter)
      Checks for JsonbAdapter on a Parameter.
      Parameters:
      parameter - parameter not null
      Returns:
      components info
    • getAnnotationFromParameterType

      private <T extends Annotation> T getAnnotationFromParameterType(Parameter parameter, Class<T> annotationClass)
    • getDeserializerBinding

      public DeserializerBinding getDeserializerBinding(JsonbAnnotatedElement<Class<?>> clsElement)
      Checks for JsonbDeserializer on a type.
      Parameters:
      clsElement - type not null
      Returns:
      components info
    • getSerializerBinding

      public SerializerBinding getSerializerBinding(Property property)
      Checks for JsonbSerializer on a property.
      Parameters:
      property - property not null
      Returns:
      components info
    • getSerializerBinding

      public SerializerBinding getSerializerBinding(JsonbAnnotatedElement<Class<?>> clsElement)
      Checks for JsonbSerializer on a type.
      Parameters:
      clsElement - type not null
      Returns:
      components info
    • getAnnotationFromPropertyType

      private <T extends Annotation> T getAnnotationFromPropertyType(Property property, Class<T> annotationClass)
    • isPropertyNillable

      public Optional<Boolean> isPropertyNillable(Property property)
      Checks if property is nillable. Looks for JsonbProperty nillable 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<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 String[] getPropertyOrder(JsonbAnnotatedElement<Class<?>> clazzElement)
      Checks for JsonbPropertyOrder annotation.
      Parameters:
      clazzElement - class to search on
      Returns:
      ordered properties names or null if not found
    • getJsonbTransientCategorized

      public 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 any JsonbTransient annotation defined for it
      Returns:
      Set of AnnotationTargets specifying in which scope the JsonbTransient is applied
    • getJsonbDateFormatCategorized

      public Map<AnnotationTarget,JsonbDateFormatter> getJsonbDateFormatCategorized(Property property)
      Search JsonbDateFormat on property, if not found looks at annotations declared on property type class.
      Parameters:
      property - Property to search on.
      Returns:
      Map of JsonbDateFormatter instances 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<Class<?>> clazzElement)
      Search for JsonbDateFormat annotation on java class and construct JsonbDateFormatter. 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<Class<?>> clazzElement)
      Search for JsonbNumberFormat annotation on java class.
      Parameters:
      clazzElement - class to search not null
      Returns:
      formatter to use
    • getJsonNumberFormatter

      public Map<AnnotationTarget,JsonbNumberFormatter> getJsonNumberFormatter(Property property)
      Search JsonbNumberFormat on property, if not found looks at annotations declared on property type class.
      Parameters:
      property - Property to search on.
      Returns:
      Map of JsonbNumberFormatter instances 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<Parameter> param)
      Returns JsonbNumberFormatter instance if JsonbNumberFormat annotation is present.
      Parameters:
      param - annotated method parameter
      Returns:
      formatter instance if JsonbNumberFormat is present otherwise null
    • getConstructorDateFormatter

      public JsonbDateFormatter getConstructorDateFormatter(JsonbAnnotatedElement<Parameter> param)
      Returns JsonbDateFormatter instance if JsonbDateFormat annotation is present.
      Parameters:
      param - annotated method parameter
      Returns:
      formatter instance if JsonbDateFormat is present otherwise null
    • createJsonbDateFormatter

      private JsonbDateFormatter createJsonbDateFormatter(String format, String locale, Property property)
      Creates JsonbDateFormatter caches 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 for
      property - 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 of getAnnotationFromProperty(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 search
      property - The property to search in
      Returns:
      A map of all occurrences of requested annotation for given property. Caller can determine based on AnnotationTarget that 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

      public void checkTransientIncompatible(JsonbAnnotatedElement<?> target)
      Finds annotations incompatible with JsonbTransient annotation.
      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

      public Set<Class<?>> collectInterfaces(Class<?> cls)
      Get class interfaces recursively.
      Parameters:
      cls - Class to process.
      Returns:
      A list of all class interfaces.
    • 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 $JsonbConstructor annotation, if set and no JsonbProperty annotations are present.
      Returns:
      Populated ClassCustomization instance.
    • getPolymorphismConfig

      private TypeInheritanceConfiguration getPolymorphismConfig(JsonbAnnotatedElement<Class<?>> clsElement, ClassCustomization parentCustomization)
    • checkDuplicityPolymorphicPropertyNames

      private void checkDuplicityPolymorphicPropertyNames(TypeInheritanceConfiguration typeInheritanceConfiguration)
    • getImplementationClass

      public Class<?> getImplementationClass(Property property)
      Returns class if ImplementationClass annotation is present.
      Parameters:
      property - annotated property
      Returns:
      Class if ImplementationClass is present otherwise null
    • collectAnnotations

      public JsonbAnnotatedElement<Class<?>> collectAnnotations(Class<?> clazz)
      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)