Class BeanMeta<T>

java.lang.Object
org.apache.juneau.BeanMeta<T>
Type Parameters:
T - The class type that this metadata applies to.
Direct Known Subclasses:
BeanMetaFiltered

public class BeanMeta<T> extends Object
Encapsulates all access to the properties of a bean class (like a souped-up 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 @Bean annotation is specified on class, then the order is the same as the list of properties in the annotation.
  • If @Bean annotation 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 @Beanp annotation defined on them.
See Also:
  • Field Details

  • Constructor Details

    • BeanMeta

      protected BeanMeta(ClassMeta<T> classMeta, BeanContext ctx, BeanFilter beanFilter, String[] pNames, ConstructorInfo implClassConstructor)
      Constructor.
      Parameters:
      classMeta - The target class.
      ctx - The bean context that created this object.
      beanFilter - Optional bean filter associated with the target class. Can be null.
      pNames - Explicit list of property names and order of properties. If null, determine automatically.
      implClassConstructor - The constructor to use if one cannot be found. Can be null.
  • Method Details

    • getClassMeta

      public final ClassMeta<T> getClassMeta()
      Returns the ClassMeta of this bean.
      Returns:
      The ClassMeta of this bean.
    • getDictionaryName

      public final String 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.
    • 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.
    • getPropertyMetas

      Returns the metadata on all properties associated with this bean.
      Returns:
      Metadata on all properties associated with this bean.
    • forEachProperty

      Performs an action on all matching properties.
      Parameters:
      filter - The filter to apply.
      action - The action to apply.
    • firstProperty

      public <T2> Optional<T2> firstProperty(Predicate<BeanPropertyMeta> filter, Function<BeanPropertyMeta,T2> function)
      Performs a function on the first property that matches the specified filter.
      Type Parameters:
      T2 - The type to convert the property to.
      Parameters:
      filter - The filter to apply.
      function - The function to apply to the matching property.
      Returns:
      The result of the function. Never null.
    • 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.
    • newBean

      protected T newBean(Object outer) throws ExecutableException
      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.
    • onReadProperty

      public Object onReadProperty(Object bean, String name, Object value)
      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

      public Object onWriteProperty(Object bean, String name, Object value)
      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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object