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< introspections = const [], BeanIntrospector? parent})Object> > -
Creates a registry holding
introspections, delegating misses toparent.
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 whenTis a nullableColor?). -
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< arguments) → BeanIntrospection<Object?> >Object> ? -
The introspection of the generic type
T(Page<Book>): the generic introspection of its class specialized with the typearguments;nullwhen 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;nullwhen there is none. -
forTypeArgument<
T> () → BeanIntrospection< Object> ? -
The introspection of
T(also whenTis a nullableBook?), here or in the parent;nullwhen there is none. -
getIntrospection(
Object bean) → BeanIntrospection< Object> -
Like findIntrospection, but throws
ArgumentErrorwhenbean's class is not introspected (or its module is not registered). -
isInstanceOf(
Type type, Object? value) → bool -
Whether
valueis oftypeor 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< introspections) → voidObject> > -
Adds every one of
introspections(see register). -
registerEnum(
EnumType< Enum> type) → void -
Makes the values of an enum (and its
@JsonValueform) known, so values of it are converted where no EnumType is at hand:ObjectMapper.readValue<Color>(...),readList<Color>, enums inObject?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 (seeBeanModule.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
typeup toObject, as registered here or in the parent;nullwhen 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
-
The process-wide registry, the default of
BeanWrapper; each context uses a child of it.final