com.vaadin.flow.internal.
Class BeanUtil
All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns whether an implementation of JSR-303 version 1.0 or 1.1 is present on the classpath.
static List<PropertyDescriptor>
getBeanPropertyDescriptors
(Class<?> beanType) Returns the property descriptors of a class, a record, or an interface.
static PropertyDescriptor
getPropertyDescriptor
(Class<?> beanType, String propertyName) Returns the property descriptor for the property of the given name and declaring class.
static Class<?>
getPropertyType
(Class<?> beanType, String propertyName) Returns the type of the property with the given name and declaring class.
-
Method Details
-
getBeanPropertyDescriptors
public static List<PropertyDescriptor> getBeanPropertyDescriptors(Class<?> beanType) throws IntrospectionException Returns the property descriptors of a class, a record, 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 queryReturns:
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 propertypropertyName
- the name of the propertyReturns:
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 propertypropertyName
- the name of the propertyReturns:
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 anIllegalStateException
. If an implementation is not found, logs a levelFINE
message the first time it is run.Returns:
true
if bean validation is available,false
otherwise.
-