Class BeanUtil

java.lang.Object
com.vaadin.flow.internal.BeanUtil
All Implemented Interfaces:
Serializable

public final class BeanUtil extends Object implements Serializable
Utility class for Java Beans information access.

For internal use only. May be renamed or removed in a future release.

Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Method Details

    • getBeanPropertyDescriptors

      public static List<PropertyDescriptor> getBeanPropertyDescriptors(Class<?> beanType) throws IntrospectionException
      Returns the property descriptors of a class or an interface. For an interface, superinterfaces are also iterated as Introspector does not take them into account (Oracle Java bug 4275879), but in that case, both the setter and the getter for a property must be in the same interface and should not be overridden in subinterfaces for the discovery to work correctly.

      NOTE : This utility method relies on introspection (and returns PropertyDescriptor) which is a part of java.beans package. The latter package could require bigger JDK in the future (with Java 9+). So it may be changed in the future.

      For interfaces, the iteration is depth first and the properties of superinterfaces are returned before those of their subinterfaces.

      Parameters:
      beanType - the type whose properties to query
      Returns:
      a list of property descriptors of the given type
      Throws:
      IntrospectionException - if the introspection fails
    • getPropertyType

      public static Class<?> getPropertyType(Class<?> beanType, String propertyName) throws IntrospectionException
      Returns the type of the property with the given name and declaring class. The property name may refer to a nested property, e.g. "property.subProperty" or "property.subProperty1.subProperty2". The property must have a public read method (or a chain of read methods in case of a nested property).
      Parameters:
      beanType - the type declaring the property
      propertyName - the name of the property
      Returns:
      the property type
      Throws:
      IntrospectionException - if the introspection fails
    • getPropertyDescriptor

      public static PropertyDescriptor getPropertyDescriptor(Class<?> beanType, String propertyName) throws IntrospectionException
      Returns the property descriptor for the property of the given name and declaring class. The property name may refer to a nested property, e.g. "property.subProperty" or "property.subProperty1.subProperty2". The property must have a public read method (or a chain of read methods in case of a nested property).
      Parameters:
      beanType - the type declaring the property
      propertyName - the name of the property
      Returns:
      the corresponding descriptor
      Throws:
      IntrospectionException - if the introspection fails
    • checkBeanValidationAvailable

      public static boolean checkBeanValidationAvailable()
      Returns whether an implementation of JSR-303 version 1.0 or 1.1 is present on the classpath. If this method returns false, trying to create a BeanValidator instance will throw an IllegalStateException. If an implementation is not found, logs a level FINE message the first time it is run.
      Returns:
      true if bean validation is available, false otherwise.