Annotation Interface Introspected


An annotation that indicates a type should produce a BeanIntrospection at compilation time.

Typically to produce a BeanIntrospection one simply annotates a class with this annotation.

 @Introspected
 public class MyBean {
      ...
 }

An alternative approach is to use a AnnotationMapper to enable introspection for existing annotations such as javax.persistence.Entity.

If the classes you wish to introspect are already compiled then this annotation can be used on another class (doesn't matter which, but typically on a configuration class) to specify which existing compiled classes to produce BeanIntrospection instances for either through the classes() method or the packages() method. The latter uses compile time package scanning and for the moment is regarded as Experimental.

 @Introspected(classes = MyBean.class)
 public class MyConfiguration {
      ...
 }
Since:
1.1
Author:
graemerocher
See Also:
  • Field Details

    • DEFAULT_ACCESS_KIND

      static final Introspected.AccessKind[] DEFAULT_ACCESS_KIND
      The default values for the access kind attribute.
    • DEFAULT_VISIBILITY

      static final Introspected.Visibility[] DEFAULT_VISIBILITY
      The default values for the visibility attribute.
  • Element Details

    • classes

      Class<?>[] classes
      By default Introspected applies to the class it is applied on. However, if classes are specified introspections will instead be generated for each class specified. This is useful in cases where you cannot alter the source code and wish to generate introspections for already compiled classes.
      Returns:
      The classes to generate introspections for
      Default:
      {}
    • classNames

      String[] classNames
      Alternative way to specify the value for `classes` when the class cannot be referenced.
      Returns:
      The class names to generate introspections for
      Default:
      {}
    • accessKind

      The default access type is Introspected.AccessKind.METHOD which treats only public JavaBean getters or Java record components as properties. By specifying Introspected.AccessKind.FIELD, public or package-protected fields will be used instead.

      If both Introspected.AccessKind.FIELD and Introspected.AccessKind.METHOD are specified then the order as they appear in the annotation will be used to determine whether the field or method will be used in the case where both exist.

      Returns:
      The access type. Defaults to Introspected.AccessKind.METHOD
      Since:
      3.0
      Default:
      {METHOD}
    • visibility

      Allows specifying the visibility policy to use to control which fields and methods are included.
      Returns:
      The visibility policies
      Since:
      3.2.0
      Default:
      {DEFAULT}
    • packages

      String[] packages

      By default Introspected applies to the class it is applied on. However if packages are specified introspections will instead be generated for each classes in the given package. Note this only applies to already compiled classes, and classpath scanning will be used to find them. If the class is not compiled then apply the annotation directly to the classs instead.

      Must be specified in combination with includedAnnotations()

      Returns:
      The packages to generate introspections for
      Default:
      {}
    • includes

      String[] includes
      The property names to include. Defaults to all properties.
      Returns:
      The names of the properties
      Default:
      {}
    • excludes

      String[] excludes
      The property names to excludes. Defaults to excluding none.
      Returns:
      The names of the properties
      Default:
      {}
    • excludedAnnotations

      Class<? extends Annotation>[] excludedAnnotations
      The annotation types that if present on the property cause the property to be excluded from results.
      Returns:
      The annotation types
      Default:
      {}
    • includedAnnotations

      Class<? extends Annotation>[] includedAnnotations
      The annotation types that if present on the property cause only the properties with the specified annotation to be included in the result.
      Returns:
      The annotation types
      Default:
      {}
    • annotationMetadata

      boolean annotationMetadata
      Whether annotation metadata should be included in the inspection results.
      Returns:
      True if annotation metadata should be included.
      Default:
      true
    • indexed

      The annotation types that should be indexed for lookup via BeanIntrospection.getIndexedProperties(Class) or BeanIntrospection.getIndexedProperty(Class, String) if Introspected.IndexedAnnotation.member() is specified.

      Property lookup indexing allows building indexes at compilation time for performing reverse property lookups. Consider for example a property with an annotation such as @Column(name = "foo_bar". To lookup the property by "foo_bar" you can specify:

       @Introspected(
         indexed = @IndexedAnnotation(annotation = Column.class, member = "name")
       )
       public class MyBean {
            ...
       }

      With the above in place a reverse lookup on the column can be done using BeanIntrospection.getIndexedProperty(Class, String):

       BeanProperty property = introspection.getIndexedProperty(Column.class, "foo_bar").orElse(null);
       
      Returns:
      The indexed annotation types
      Default:
      {}
    • withPrefix

      String withPrefix
      Returns:
      The prefix used for copy constructor invoking methods on immutable types. The default is "with".
      Since:
      2.3.0
      Default:
      "with"
    • targetPackage

      String targetPackage
      Returns:
      The package to write introspections to. By default, uses the class package.
      Since:
      3.9.0
      Default:
      ""
    • ignoreSettersWithDifferingType

      @NextMajorVersion("Consider switching to false") boolean ignoreSettersWithDifferingType
      If the introspection should ignore a setter with a different type than a getter. NOTE: Access the correct a read/write type by using BeanIntrospection.getBeanWriteProperties() / BeanIntrospection.getBeanReadProperties() ()}
      Returns:
      true if to ignore.
      Since:
      4.4.0
      Default:
      true
    • builder

      Allows specifying a builder for the introspection.
      Returns:
      The builder definition for the introspection.
      Since:
      4.1.0
      Default:
      @io.micronaut.core.annotation.Introspected.IntrospectionBuilder