BeanIntrospection<T extends Object> class final

Everything the generator knows about an introspected class: its properties, methods, constructor and annotations, with closures to use them.

It replaces reflection: BeanWrapper, data binding, validation, SpEL and ObjectMapper read and create objects through it. The generator writes one per @Introspected class and the module registers it in a BeanIntrospector; you write one by hand only for a class the generator cannot see. Micronaut's BeanIntrospection is the same idea.

// A hand-written introspection of Address, then used by name.
final addressIntrospection = BeanIntrospection<Address>(
  properties: [
    BeanProperty<Address>(
      'city',
      type: String,
      get: (b) => b.city,
      set: (b, v) => b.city = v! as String,
    ),
  ],
  instantiate: Address.new,
);

final address = addressIntrospection.instantiate();
addressIntrospection.getProperty('city')!.setValue(address, 'Lyon');

Spring (Java): no direct counterpart. Spring uses runtime reflection (BeanUtils, java.beans.BeanInfo, PropertyDescriptor):

BeanInfo info = Introspector.getBeanInfo(Address.class);
Address address = BeanUtils.instantiateClass(Address.class);

Constructors

BeanIntrospection({List<BeanProperty<T>> properties = const [], List<BeanMethod<T>> methods = const [], List<Object> annotations = const [], Set<IntrospectionPart> parts = const {IntrospectionPart.read, IntrospectionPart.write, IntrospectionPart.methods}, T instantiate()?, BeanConstructor<T>? constructor, T fromJson(Object? json)?, Object? toJson(T bean)?, String? className, BeanIntrospection<Object> specialize(List<TypeInfo<Object?>> arguments)?})
The description of T. instantiate calls the no-argument constructor, if there is one; the other closures are written by the generator. parts lists what the description holds (the generator leaves out what the build saw nothing use); a hand-written one holds everything.

Properties

annotations → List<Object>
The const annotations on the class.
final
beanType → Type
The introspected class.
no setter
className → String
The simple name of the class, without type arguments (written by the generator, so it survives minification; e.g. the default JSON type id).
no setter
constructor → BeanConstructor<T>?
The constructor to create instances from data (ObjectMapper), when the class has a usable one.
final
hasFromJson → bool
Whether the class has its own fromJson constructor (e.g. from json_serializable or freezed), which ObjectMapper then uses.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hasToJson → bool
Whether the class has its own toJson() method.
no setter
isGeneric → bool
Whether this describes a generic class with its type parameters erased (Page<Object?> for Page<T>) that can be specialized.
no setter
isInstantiable → bool
Whether instantiate is available (a no-argument constructor).
no setter
methods → Iterable<BeanMethod<T>>
All public instance methods, in declaration order.
no setter
parts → Set<IntrospectionPart>
What this description holds of the class; the generator leaves out the parts it saw nothing use (see IntrospectionPart).
final
properties → Iterable<BeanProperty<T>>
All properties, in declaration order.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

describes<S>() → bool
Whether S is T or T?.
describesPart(IntrospectionPart part) → bool
Whether this description holds part.
fromJson(Object? json) → T
Calls the class's own fromJson with json.
getMethod(String name) → BeanMethod<T>?
The method named name, or null (Dart has no overloads).
getProperty(String name) → BeanProperty<T>?
The property named name, or null.
instantiate() → T
Creates a new instance with the no-argument constructor; throws StateError when isInstantiable is false, an IntrospectionPartError when the description has no IntrospectionPart.write.
isInstance(Object? value) → bool
Whether value is a T (or a subtype).
isRawTypeOf<S>() → bool
Whether S is a parameterization of the class this describes (Page<Book> for Page<Object?>).
isSubtypeOf(BeanIntrospection<Object> other) → bool
Whether T is a subtype of the class other describes.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requirePart(IntrospectionPart part, String use) → void
Throws an IntrospectionPartError unless this description holds part; use says what needs it (it is written out as JSON).
specialize(List<TypeInfo<Object?>> arguments) → BeanIntrospection<Object>
The introspection of this generic class with the type arguments (Page<Book> for [ClassType<Book>()]): constructor parameters and properties typed with them. Throws StateError when not isGeneric.
toJson(Object bean) → Object?
Calls the class's own toJson() on bean.
toString() → String
A string representation of this object.
override

Operators

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