BeanIntrospector class

The registry that finds the BeanIntrospection of a class or object.

Code that reads objects without reflection asks it for their description. Each application context has its own introspector (the bean beanIntrospector), filled from its modules, with shared as parent; lookups that fail here go to the parent. Applications rarely use it directly; BeanWrapper and ObjectMapper do. Micronaut's BeanIntrospector is the same idea.

// List the property names of any introspected object.
final introspector = BeanIntrospector(
  introspections: [personIntrospection, addressIntrospection],
);
final meta = introspector.getIntrospection(person);
log.info(meta.properties.map((p) => p.name));

Spring (Java): no counterpart; Spring introspects any class at runtime (cached by CachedIntrospectionResults):

PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(Person.class);

Constructors

BeanIntrospector({Iterable<BeanIntrospection<Object>> introspections = const [], BeanIntrospector? parent})
Creates a registry holding introspections, delegating misses to parent.

Properties

hashCode → int
The hash code for this object.
no setterinherited
introspections → Iterable<BeanIntrospection<Object>>
Every registered introspection, this registry's first, then the parent's.
no setter
parent → BeanIntrospector?
The registry consulted when this one has no match.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

enumTypeFor(Type type) → EnumType<Enum>?
The registered EnumType of the enum type (here, else in the parent).
enumTypeOf<T>() → EnumType<Enum>?
The registered EnumType of the enum T (also when T is a nullable Color?).
findIntrospection(Object bean) → BeanIntrospection<Object>?
The introspection for bean: its exact runtime type (here or in a parent), else the most specific registered supertype (here, then in the parent).
forGenericType<T>(List<TypeInfo<Object?>> arguments) → BeanIntrospection<Object>?
The introspection of the generic type T (Page<Book>): the generic introspection of its class specialized with the type arguments; null when its class is not introspected (or not generic). Cached per type.
forType(Type type) → BeanIntrospection<Object>?
The introspection registered for exactly type, here or in the parent; null when there is none.
forTypeArgument<T>() → BeanIntrospection<Object>?
The introspection of T (also when T is a nullable Book?), here or in the parent; null when there is none.
getIntrospection(Object bean) → BeanIntrospection<Object>
Like findIntrospection, but throws ArgumentError when bean's class is not introspected (or its module is not registered).
isInstanceOf(Type type, Object? value) → bool
Whether value is of type or of a subtype of it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(BeanIntrospection<Object> introspection) → void
Adds introspection, replacing any for the same type. The enums its properties and constructor parameters use are registered too (see registerEnum).
registerAll(Iterable<BeanIntrospection<Object>> introspections) → void
Adds every one of introspections (see register).
registerEnum(EnumType<Enum> type) → void
Makes the values of an enum (and its @JsonValue form) known, so values of it are converted where no EnumType is at hand: ObjectMapper.readValue<Color>(...), readList<Color>, enums in Object? properties or map values. The enums the properties and constructor parameters of registered introspections use are registered automatically; the first registration of an enum wins.
registerTypeDepths(Map<Type, int> depths) → void
Adds depths, the supertype chain length of each type (see BeanModule.typeDepths).
registerTypeTests(Map<Type, bool Function(Object? value)> tests) → void
Adds tests, each telling whether a value is of its type (or a subtype); the generated modules give one per type written in an annotation.
toString() → String
A string representation of this object.
inherited
typeDepth(Type type) → int?
The length of the longest chain of supertypes from type up to Object, as registered here or in the parent; null when no module described it. Of two types a value is an instance of, the one with the greater depth is the closer to the value's class.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

shared → BeanIntrospector
The process-wide registry, the default of BeanWrapper; each context uses a child of it.
final