BeanProperty<T extends Object> class
final
The description of one property of an introspected class: its name, type, annotations, and closures that read and write it.
The generator writes these for @Introspected classes; BeanWrapper,
validation and SpEL use them to reach a field by name. You write one by
hand only in a hand-written BeanIntrospection.
Both closures are optional: the generator writes only the ones the
application uses (see IntrospectionPart), so a property that is only
read from JSON has a setter and no getter (isReadable is false).
// A property of Address, written by hand.
final city = BeanProperty<Address>(
'city',
type: String,
get: (b) => b.city,
set: (b, v) => b.city = v! as String,
annotations: const [NotBlank()],
);
city.setValue(address, 'Lyon');
city.getValue(address); // 'Lyon'
Spring (Java): java.beans.PropertyDescriptor, found by reflection:
PropertyDescriptor city =
BeanUtils.getPropertyDescriptor(Address.class, "city");
city.getWriteMethod().invoke(address, "Lyon");
Constructors
-
BeanProperty(String name, {required Type type, Object? get(T bean)?, void set(T bean, Object? value)?, bool nullable = false, TypeInfo<
Object?> ? typeInfo, bool hasInitialValue = false, Object? initialValue, List<Object> annotations = const []}) -
Describes the property
nameofTwith the declaredtype; omitsetfor a read-only property andgetfor a write-only one.
Properties
-
annotations
→ List<
Object> -
The const annotations on the field or getter (e.g. constraints).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasInitialValue → bool
-
Whether the field is declared with an initializer that is a constant
the generator could write into the description, so initialValue is
meaningful (
bool inStock = true).final - initialValue → Object?
-
The constant the field starts with, when hasInitialValue is
true(nullfor an initializer that isnull, or when it is not).final - isReadable → bool
-
Whether the property can be read;
falsewhen the description has no getter for it (the build saw nothing read the class).no setter - isWritable → bool
-
Whether the property can be written;
falsefor a final field or a getter without a setter.no setter - name → String
-
The name of the field or getter.
final
- nullable → bool
-
Whether the declared type is nullable.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- type → Type
-
The declared type, without its nullability (see nullable).
final
-
typeInfo
→ TypeInfo<
Object?> ? -
The full declared type (element types, enum values, nullability);
written by the generator,
nullin hand-written introspections.final
Methods
-
annotationsOf<
A> () → Iterable< A> -
The annotations of the property of type
A. -
getValue(
Object bean) → Object? -
The value of the property in
bean, which must be aT. Throws an IntrospectionPartError when the property has no getter (isReadable). -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setValue(
Object bean, Object? value) → void -
Writes
valueinto the property ofbean. The value must already have the property's type (BeanWrapperconverts first). ThrowsStateErrorfor a read-only property. -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited