Class AnnotationDefaults

java.lang.Object
io.micronaut.inject.annotation.AnnotationDefaults

@Internal public final class AnnotationDefaults extends Object
The defaults an annotation type declares, read from the type itself and keyed by the type.

AnnotationMetadataSupport.getDefaultValues(String) answers from a registry keyed by annotation name, which generated code fills in as classes load. That registry serves the accessors of metadata built at compilation time, where the defaults are written into the generated class; it is the wrong source for anything that has the annotation type in hand, for two reasons. It is mutable and filled in over the life of the process, so the same question can be answered differently depending on what has been loaded, and it is keyed by name, so the same annotation name defined by two class loaders resolves to whichever was registered last.

What is read here is a property of the type alone: the Method.getDefaultValue() of each of its members, converted into the shapes the metadata records values in. A ClassValue keys it by the class rather than the name, so two deployments of the same annotation name keep their own defaults, and nothing outside can change what a type answers.

Since:
5.2.0
Author:
Denis Stepanov
  • Method Details

    • membersOf

      public static List<Method> membersOf(Class<? extends Annotation> annotationType)
      The members of an annotation type, made accessible - the type may not be public - and ordered by name.
      Parameters:
      annotationType - The annotation type
      Returns:
      The members, unmodifiable
    • of

      public static Map<CharSequence, Object> of(Class<? extends Annotation> annotationType)
      The defaults of an annotation type, in the shapes the metadata records values in.
      Parameters:
      annotationType - The annotation type
      Returns:
      The defaults by member name, unmodifiable and never null
    • convert

      public static Object convert(Object value)
      A member value as the metadata records it: a class as an AnnotationClassValue, an enum by the name of its constant and a nested annotation as an AnnotationValue, arrays of each likewise.
      Parameters:
      value - The value read off the annotation type
      Returns:
      The recorded form