Class BeanPropertyMeta
- All Implemented Interfaces:
Comparable<BeanPropertyMeta>
Contains information such as type of property (e.g. field/getter/setter), class type of property value, and whether any transforms are associated with this property.
Developers will typically not need access to this class. The information provided by it is already exposed through
several methods on the BeanMap API.
Thread safety
Instances are immutable after construction and are safe for concurrent read access.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBeanPropertyMeta builder class. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObjectSentinel value that, when returned fromBeanPropertyMeta.Builder.writeTransformduringset(BeanMap, String, Object), causes the set to be skipped entirely — neither the configured setter is invoked nor the property cache updated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new BeanPropertyMeta using the contents of the specified builder. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a value to aCollectionor array property.voidAdds a value to aMapor bean property.static BeanPropertyMeta.BuilderCreates a builder forBeanPropertyMeta(org.apache.juneau.commons.bean.BeanPropertyMeta.Builder)objects.booleancanRead()Returnstrue if this property can be read.booleancanWrite()Returnstrue if this property can be written.intbooleanEquivalent to callingBeanMap.get(Object), but is faster since it avoids looking up the property meta.Returns all annotations on this property (field, getter, and setter).<A extends Annotation>
Stream<AnnotationInfo<A>>getAnnotations(Class<A> a) Returns a stream of annotations of the specified type on this property.BeanInfo<?>Returns theBeanInfoof the class of this property.BeanMeta<?>Returns the bean meta that this property belongs to.Returns the bean dictionary in use for this bean property.Returns the metadata on the property that this metadata is a delegate for.getDynaMap(Object bean) Returns theMapobject returned by the DynaBean getter.getField()Returns the field for this property.Returns the getter method for this property.Returns the field for this property even if the field is private.getName()Returns the name of this bean property.Equivalent to callingBeanMap.getRaw(Object), but is faster since it avoids looking up the property meta.Returns the setter method for this property.getViews()Returns the set of named views this property belongs to, ornull if the property is untagged.inthashCode()booleanisDyna()Returnstrue if this bean property is named"*" .booleanReturnstrue if this property is read-only.booleanReturns whether this property is marked@BeanProp(required=true).booleanisUri()Returnstrue if this bean property is a URI.booleanReturnstrue if this property is write-only.Equivalent to callingBeanMap.put(String, Object), but is faster since it avoids looking up the property meta.protected voidSets an array field on this bean.toString()
-
Field Details
-
SKIP_VALUE
Sentinel value that, when returned fromBeanPropertyMeta.Builder.writeTransformduringset(BeanMap, String, Object), causes the set to be skipped entirely — neither the configured setter is invoked nor the property cache updated.Provided as a generic SPI hook so the marshalling layer (or any other transform-installing extension) can implement "leave the bean's pre-existing value in place" semantics — used by the per-property null-coercion
SKIPmode added to the marshalling layer in 10.0.0.- Since:
- 10.0.0
-
-
Constructor Details
-
BeanPropertyMeta
Creates a new BeanPropertyMeta using the contents of the specified builder.- Parameters:
b- The builder to copy fields from. Must not benull .
-
-
Method Details
-
builder
Creates a builder forBeanPropertyMeta(org.apache.juneau.commons.bean.BeanPropertyMeta.Builder)objects.- Parameters:
beanMeta- The metadata on the bean. Must not benull .name- The bean property name.- Returns:
- A new builder.
-
add
Adds a value to aCollectionor array property.Note that adding values to an array property is inefficient for large arrays since it must copy the array into a larger array on each operation.
Marshalling-only path. Requires a property built via the marshalling-side construction path (i.e. with a non-null
rawTypeMetaand a non-null backingMarshallingSessionon the suppliedBeanMap). When the owningBeanMetawas built viaBeanMeta.of(Class, BeanConfigContext), this method throwsUnsupportedOperationExceptionbecause adding into a Collection/array property requires type-aware element conversion (the marshalling session'sconvertToType) that is not available in the bean-modeling-only path.- Parameters:
m- The bean of the field being set.pName- The property name if this is a dyna property (i.e."*" ).
Otherwise can benull .value- The value to add to the field. Can benull .- Throws:
BeanRuntimeException- If field is not a collection or array.UnsupportedOperationException- If this property was built via the bean-modeling-only path (BeanMeta.of(Class, BeanConfigContext)).
-
add
Adds a value to aMapor bean property.Marshalling-only path. Requires a property built via the marshalling-side construction path (i.e. with a non-null
rawTypeMetaand a non-null backingMarshallingSessionon the suppliedBeanMap). When the owningBeanMetawas built viaBeanMeta.of(Class, BeanConfigContext), this method throwsUnsupportedOperationExceptionbecause adding into a Map/bean property requires type-aware value conversion (the marshalling session'sconvertToType/toBeanMap) that is not available in the bean-modeling-only path.- Parameters:
m- The bean of the field being set.pName- The property name if this is a dyna property (i.e."*" ).
Otherwise can benull .key- The key to add to the field.value- The value to add to the field. Can benull .- Throws:
BeanRuntimeException- If field is not a map or array.UnsupportedOperationException- If this property was built via the bean-modeling-only path (BeanMeta.of(Class, BeanConfigContext)).
-
canRead
Returnstrue if this property can be read.Write-only properties (see
isWriteOnly()) are never readable, so serializers, tabular column sets and schemas skip them. They remain settable throughcanWrite()and parsing.- Returns:
true if this property can be read.
-
canWrite
Returnstrue if this property can be written.- Returns:
true if this property can be written.
-
compareTo
- Specified by:
compareToin interfaceComparable<BeanPropertyMeta>
-
equals
-
getAnnotations
Returns all annotations on this property (field, getter, and setter).The annotations are found on:
- The field (if present)
- The getter method (if present) - including annotations on the method, its return type, and package
- The setter method (if present) - including annotations on the method, its return type, and package
The result is memoized and computed only once.
- Returns:
- A list of all annotation infos on this property. Never
null .
-
getAnnotations
Returns a stream of annotations of the specified type on this property.The annotations are found on:
- The field (if present)
- The getter method (if present) - including annotations on the method, its return type, and package
- The setter method (if present) - including annotations on the method, its return type, and package
- Type Parameters:
A- The annotation type to find.- Parameters:
a- The annotation class to find. Can benull , in which case an empty stream is returned.- Returns:
- A stream of annotation infos of the specified type. Never
null .
-
get
Equivalent to callingBeanMap.get(Object), but is faster since it avoids looking up the property meta.- Parameters:
m- The bean map to get the transformed value from.pName- The property name if this is a dyna property (i.e."*" ).
Otherwise can benull .- Returns:
- The property value.
Returnsnull if this is a write-only property.
-
getBeanMeta
Returns the bean meta that this property belongs to.- Returns:
- The bean meta that this property belongs to.
-
getBeanRegistry
Returns the bean dictionary in use for this bean property.The order of lookup for the dictionary is as follows:
- Dictionary defined via
@MarshalledProp(dictionary). - Dictionary defined via
MarshallingContext.Builder<?>#beanDictionary(Class...).
The per-property registry no longer lives on this object; it is stored in a marshalling-side side-map on
BeanMetakeyed byBeanPropertyMeta. This method delegates toBeanMeta.getPropertyBeanRegistry(BeanPropertyMeta)for backwards compatibility with existing call sites in the marshalling layer (parser/serializer sessions, XML content-property handling, etc.).Returns the bean-modeling-side SPI type (
BeanRegistryLookup). Marshalling-side callers that need implementation-specific behavior cast at the call site.- Returns:
- The bean dictionary in use for this bean property, or
null if no registry was registered.
- Dictionary defined via
-
getBeanInfo
Returns theBeanInfoof the class of this property.If this property or the property type class has a
ObjectSwapassociated with it, this method returns the transformed class meta. This matches the class type that is used by theget(BeanMap,String)andset(BeanMap,String,Object)methods.Returns the bean-modeling-side SPI type (
BeanInfo). Marshalling-side callers that need theClassMetanarrowing must cast — the concrete instance in-tree is always aClassMeta.- Returns:
- The
BeanInfoof the class of this property, ornull if this property was built via the bean-modeling-only path.
-
getDelegateFor
Returns the metadata on the property that this metadata is a delegate for.- Returns:
- the metadata on the property that this metadata is a delegate for, or this object if it's not a delegate.
-
getDynaMap
public Map<String,Object> getDynaMap(Object bean) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException Returns theMapobject returned by the DynaBean getter.The DynaBean property is the property whose name is
"*" and returns a map of "extra" properties on the bean.- Parameters:
bean- The bean.- Returns:
- The map returned by the getter, or an empty map if the getter returned
null or this isn't a DynaBean property. - Throws:
IllegalArgumentException- Thrown by method invocation.IllegalAccessException- Thrown by method invocation.InvocationTargetException- Thrown by method invocation.
-
getField
Returns the field for this property.- Returns:
- The field info for this bean property, or
null if there is no field associated with this bean property.
-
getGetter
Returns the getter method for this property.- Returns:
- The getter method info for this bean property, or
null if there is no getter method.
-
getInnerField
Returns the field for this property even if the field is private.- Returns:
- The field info for this bean property, or
null if there is no field associated with this bean property.
-
getName
Returns the name of this bean property.- Returns:
- The name of the bean property.
-
getRaw
Equivalent to callingBeanMap.getRaw(Object), but is faster since it avoids looking up the property meta.- Parameters:
m- The bean map to get the transformed value from.pName- The property name if this is a dyna property (i.e."*" ).
Otherwise can benull .- Returns:
- The raw property value.
-
getSetter
Returns the setter method for this property.- Returns:
- The setter method info for this bean property, or
null if there is no setter method.
-
hashCode
-
isDyna
Returnstrue if this bean property is named"*" .- Returns:
true if this bean property is named"*" .
-
isRequired
Returns whether this property is marked@BeanProp(required=true).Required properties must be present in parser input (or in the source map of a
Map-to-bean conversion); seeBeanProp.required().- Returns:
true if this property is required.
-
isReadOnly
Returnstrue if this property is read-only.This implies the property MIGHT be writable, but that parsers should not set a value for it.
- Returns:
true if this property is read-only.
-
isUri
Returnstrue if this bean property is a URI.A bean property can be considered a URI if any of the following are true:
- Returns:
true if this bean property is a URI.
-
getViews
Returns the set of named views this property belongs to, ornull if the property is untagged.An untagged property (one with no
@MarshalledProp(view=...)annotation) follows the default-view-inclusion policy: it is included under every active view when the policy is enabled (the default behavior), or excluded from all views when the policy is disabled.A tagged property is included only when the active view name is contained in this set.
- Returns:
- The set of named views, or
null if no view membership was declared.
-
set
Equivalent to callingBeanMap.put(String, Object), but is faster since it avoids looking up the property meta.This is a no-op on a read-only property.
- Parameters:
m- The bean map to set the property value on.pName- The property name if this is a dyna property (i.e."*" ).
Otherwise can benull .value- The value to set. Can benull to set the property tonull .- Returns:
- The previous property value.
- Throws:
BeanRuntimeException- If property could not be set.
-
properties
-
toString
-
isWriteOnly
Returnstrue if this property is write-only.This implies the property MIGHT be readable, but that serializers should not serialize it.
- Returns:
true if this property is write-only.
-
setArray
protected void setArray(Object bean, List l) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException Sets an array field on this bean.Works on both
Object and primitive arrays.Marshalling-only path. Requires a property built via the marshalling-side construction path (i.e. with a non-null
rawTypeMeta). When the owningBeanMetawas built viaBeanMeta.of(Class, BeanConfigContext), this method throwsUnsupportedOperationExceptionbecause the array element type is only known viarawTypeMeta, which is not populated in the bean-modeling-only path.- Parameters:
bean- The bean of the field.l- The collection to use to set the array field.- Throws:
IllegalArgumentException- Thrown by method invocation.IllegalAccessException- Thrown by method invocation.InvocationTargetException- Thrown by method invocation.UnsupportedOperationException- If this property was built via the bean-modeling-only path (BeanMeta.of(Class, BeanConfigContext)).
-