Class BeanMeta<T>
- Type Parameters:
T- The class type that this metadata applies to.
- Direct Known Subclasses:
BeanMetaFiltered
BeanInfo).
Description
Uses introspection to find all the properties associated with this class. If the@Bean annotation
is present on the class, then that information is used to determine the properties on the class.
Otherwise, the BeanInfo functionality in Java is used to determine the properties on the class.
Bean property ordering
The order of the properties are as follows:-
If
@Beanannotation is specified on class, then the order is the same as the list of properties in the annotation. -
If
@Beanannotation is not specified on the class, then the order is based on the following.- Public fields (same order as
Class.getFields()). - Properties returned by
BeanInfo.getPropertyDescriptors(). - Non-standard getters/setters with
@Beanpannotation defined on them.
- Public fields (same order as
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> org.apache.juneau.BeanMeta.BeanMetaValue<T>Creates aBeanMetainstance for the specified class metadata.booleanprotected BeanContextReturns the bean context that created this metadata object.Returns the bean filter associated with this bean.Returns the proxy invocation handler for this bean if it's an interface.Returns the bean registry for this bean.Returns theClassMetaof this bean.protected ConstructorInfoReturns the constructor for this bean, if one was found.Returns the list of property names that correspond to the constructor parameters.Returns the dictionary name for this bean as defined through the@Bean(typeName)annotation.protected BeanPropertyMetaReturns the "extras" property for dynamic bean properties.Returns the map of getter methods to property names.protected Map<String,BeanPropertyMeta> Returns the map of hidden properties on this bean.Returns a map of all properties on this bean.getPropertyMeta(String name) Returns metadata about the specified property.Returns the map of setter methods to property names.Returns a mock bean property that resolves to the name"_type" and whose value always resolves to the dictionary name of the bean.Returns the type property name for this bean.protected booleanReturns whether this bean has a constructor available for instantiation.inthashCode()protected booleanReturns whether properties should be sorted for this bean.protected TCreates a new instance of this bean.onReadProperty(Object bean, String name, Object value) Property read interceptor.onWriteProperty(Object bean, String name, Object value) Property write interceptor.toString()
-
Constructor Details
-
BeanMeta
Constructor.Creates a new
BeanMetainstance for the specified class metadata. This constructor performs introspection to discover all bean properties, methods, and fields in the class hierarchy.The bean metadata is built by:
- Finding all bean fields in the class hierarchy
- Finding all bean methods (getters, setters, extraKeys) in the class hierarchy
- Determining the appropriate constructor for bean instantiation
- Building the class hierarchy for property discovery
- Creating the bean registry for dictionary name resolution
- Validating and filtering properties based on bean filter settings
- Parameters:
cm- The class metadata for the bean class.bf- Optional bean filter to apply. Can benull .pNames- Explicit list of property names and order. Ifnull , properties are determined automatically.implClass- Optional implementation class constructor to use if one cannot be found. Can benull .
-
-
Method Details
-
create
public static <T> org.apache.juneau.BeanMeta.BeanMetaValue<T> create(ClassMeta<T> cm, ClassInfo implClass) Creates aBeanMetainstance for the specified class metadata.This is a factory method that attempts to create bean metadata for a class. If the class is determined to be a bean, the returned
BeanMeta.BeanMetaValuewill contain theBeanMetainstance and anull reason. If the class is not a bean, the returned value will containnull for the bean metadata and a non-null string explaining why it's not a bean.Parameters:
- cm - The class metadata for the class to create bean metadata for.
- bf - Optional bean filter to apply. Can be
null . - pNames - Explicit list of property names and order. If
null , properties are determined automatically. - implClassConstructor - Optional constructor to use if one cannot be found. Can be
null .
Return Value:
Returns a
BeanMeta.BeanMetaValuecontaining:- beanMeta - The bean metadata if the class is a bean, or
null if it's not. - notABeanReason - A string explaining why the class is not a bean, or
null if it is a bean.
Exception Handling:
If a
RuntimeExceptionis thrown during bean metadata creation, it is caught and the exception message is returned as thenotABeanReason withnull for the bean metadata.Example:
// Create bean metadata for a class ClassMeta<Person>cm =beanContext .getClassMeta(Person.class ); BeanMetaValue<Person>result = BeanMeta.create (cm ,null ,null ,null );// Check if it's a bean if (result .beanMeta() !=null ) { BeanMeta<Person>bm =result .beanMeta();// Use the bean metadata... }else { Stringreason =result .notABeanReason();// Handle the case where it's not a bean... }- Type Parameters:
T- The class type.- Parameters:
cm- The class metadata for the class to create bean metadata for.implClass- The implementation class info.- Returns:
- A
BeanMeta.BeanMetaValuecontaining the bean metadata (if successful) or a reason why it's not a bean.
-
equals
-
getBeanFilter
Returns the bean filter associated with this bean.Bean filters are used to control aspects of how beans are handled during serialization and parsing, such as property inclusion/exclusion, property ordering, and type name mapping.
The bean filter is typically created from the
@Beanannotation on the class. If no@Beanannotation is present, this method returnsnull .- Returns:
- The bean filter for this bean, or
null if no bean filter is associated with this bean. - See Also:
-
getBeanProxyInvocationHandler
Returns the proxy invocation handler for this bean if it's an interface.- Returns:
- The invocation handler, or
null if this is not an interface or interface proxies are disabled.
-
getBeanRegistry
Returns the bean registry for this bean.The bean registry is used to resolve dictionary names to class types. It's created when a bean class has a
@Bean(dictionary)annotation that specifies a list of possible subclasses.- Returns:
- The bean registry for this bean, or
null if no bean registry is associated with it.
-
getClassMeta
Returns theClassMetaof this bean.- Returns:
- The
ClassMetaof this bean.
-
getDictionaryName
Returns the dictionary name for this bean as defined through the@Bean(typeName)annotation.- Returns:
- The dictionary name for this bean, or
null if it has no dictionary name defined.
-
getProperties
Returns a map of all properties on this bean.The map is keyed by property name and contains
BeanPropertyMetaobjects that provide metadata about each property, including its type, getter/setter methods, field information, and serialization/parsing behavior.This map contains only the normal (non-hidden) properties of the bean. Hidden properties can be accessed via
getHiddenProperties().- Returns:
- A map of property names to their metadata. The map is unmodifiable.
- See Also:
-
getPropertyMeta
Returns metadata about the specified property.- Parameters:
name- The name of the property on this bean.- Returns:
- The metadata about the property, or
null if no such property exists on this bean.
-
getTypeProperty
Returns a mock bean property that resolves to the name"_type" and whose value always resolves to the dictionary name of the bean.- Returns:
- The type name property.
-
getTypePropertyName
Returns the type property name for this bean.This is the name of the bean property used to store the dictionary name of a bean type so that the parser knows the data type to reconstruct.
If
null ,"_type" should be assumed.The value is determined from:
- The
@Bean(typePropertyName)annotation on the class, if present. - Otherwise, the default value from
BeanContext.getBeanTypePropertyName().
- Returns:
- The type property name associated with this bean, or
null if the default"_type" should be used. - See Also:
- The
-
hashCode
-
onReadProperty
Property read interceptor.Called immediately after calling the getter to allow the value to be overridden.
- Parameters:
bean- The bean from which the property was read.name- The property name.value- The value just extracted from calling the bean getter.- Returns:
- The value to serialize. Default is just to return the existing value.
-
onWriteProperty
Property write interceptor.Called immediately before calling theh setter to allow value to be overwridden.
- Parameters:
bean- The bean from which the property was read.name- The property name.value- The value just parsed.- Returns:
- The value to serialize. Default is just to return the existing value.
-
properties
-
toString
-
getBeanContext
Returns the bean context that created this metadata object.- Returns:
- The bean context.
-
getConstructor
Returns the constructor for this bean, if one was found.The constructor is determined by
findBeanConstructor()and may be:- A constructor annotated with
@Beanc - An implementation class constructor (if provided)
- A no-argument constructor
null if no suitable constructor was found
- Returns:
- The constructor for this bean, or
null if no constructor is available. - See Also:
- A constructor annotated with
-
getConstructorArgs
Returns the list of property names that correspond to the constructor parameters.The property names are in the same order as the constructor parameters. These names are used to map parsed property values to constructor arguments when creating bean instances.
The property names are determined from:
- The
properties()value in the@Beancannotation (if present) - Otherwise, the parameter names from the constructor (if available in bytecode)
If the bean has no constructor or uses a no-argument constructor, this list will be empty.
- Returns:
- A list of property names corresponding to constructor parameters, in parameter order.
- See Also:
- The
-
getDynaProperty
Returns the "extras" property for dynamic bean properties.- Returns:
- The dynamic property, or
null if not present.
-
getGetterProps
Returns the map of getter methods to property names.- Returns:
- The getter properties map.
-
getHiddenProperties
Returns the map of hidden properties on this bean.Hidden properties are properties that exist on the bean but are not included in the normal property list. These properties are typically excluded from serialization but may still be accessible programmatically.
Hidden properties can be defined through:
Bean filter exclude properties- Properties that fail validation during bean metadata creation
- Returns:
- A map of hidden property names to their metadata. The map is unmodifiable.
- See Also:
-
getSetterProps
Returns the map of setter methods to property names.- Returns:
- The setter properties map.
-
hasConstructor
Returns whether this bean has a constructor available for instantiation.A bean has a constructor if
findBeanConstructor()was able to find a suitable constructor, which may be:- A constructor annotated with
@Beanc - An implementation class constructor (if provided)
- A no-argument constructor
If this method returns
false , the bean cannot be instantiated usingnewBean(Object), and may need to be created through other means (e.g., interface proxies).- Returns:
true if a constructor is available,false otherwise.- See Also:
- A constructor annotated with
-
isSortProperties
Returns whether properties should be sorted for this bean.- Returns:
true if properties should be sorted.
-
newBean
Creates a new instance of this bean.- Parameters:
outer- The outer object if bean class is a non-static inner member class.- Returns:
- A new instance of this bean if possible, or
null if not. - Throws:
ExecutableException- Exception occurred on invoked constructor/method/field.
-