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< properties = const [], List<T> >BeanMethod< methods = const [], List<T> >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< arguments)?})Object?> > -
The description of
T.instantiatecalls the no-argument constructor, if there is one; the other closures are written by the generator.partslists 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
fromJsonconstructor (e.g. fromjson_serializableorfreezed), whichObjectMapperthen 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?>forPage<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
SisTorT?. -
describesPart(
IntrospectionPart part) → bool -
Whether this description holds
part. -
fromJson(
Object? json) → T -
Calls the class's own
fromJsonwithjson. -
getMethod(
String name) → BeanMethod< T> ? -
The method named
name, ornull(Dart has no overloads). -
getProperty(
String name) → BeanProperty< T> ? -
The property named
name, ornull. -
instantiate(
) → T -
Creates a new instance with the no-argument constructor; throws
StateErrorwhen isInstantiable isfalse, an IntrospectionPartError when the description has no IntrospectionPart.write. -
isInstance(
Object? value) → bool -
Whether
valueis aT(or a subtype). -
isRawTypeOf<
S> () → bool -
Whether
Sis a parameterization of the class this describes (Page<Book>forPage<Object?>). -
isSubtypeOf(
BeanIntrospection< Object> other) → bool -
Whether
Tis a subtype of the classotherdescribes. -
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;usesays what needs it (it is written out as JSON). -
specialize(
List< TypeInfo< arguments) → BeanIntrospection<Object?> >Object> -
The introspection of this generic class with the type
arguments(Page<Book>for[ClassType<Book>()]): constructor parameters and properties typed with them. ThrowsStateErrorwhen not isGeneric. -
toJson(
Object bean) → Object? -
Calls the class's own
toJson()onbean. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited