public BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) { super(propertyName, calculateMatches(propertyName, BeanUtils.getPropertyDescriptors(beanClass), maxDistance)); }
/** * Find a JavaBeans {@code PropertyDescriptor} for the given method, * with the method either being the read method or the write method for * that bean property. * @param method the method to find a corresponding PropertyDescriptor for * @param clazz the (most specific) class to introspect for descriptors * @return the corresponding PropertyDescriptor, or {@code null} if none * @throws BeansException if PropertyDescriptor lookup fails * @since 3.2.13 */ @Nullable public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException { Assert.notNull(method, "Method must not be null"); PropertyDescriptor[] pds = getPropertyDescriptors(clazz); for (PropertyDescriptor pd : pds) { if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) { return pd; } } return null; }
public DefaultToStringOperator(Class<T> targetType) { this.targetType = targetType; descriptors = BeanUtils.getPropertyDescriptors(targetType); init(); }
/** * Initialize the mapping meta-data for the given class. * @param mappedClass the mapped class */ protected void initialize(Class<T> mappedClass) { this.mappedClass = mappedClass; this.mappedFields = new HashMap<>(); this.mappedProperties = new HashSet<>(); PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass); for (PropertyDescriptor pd : pds) { if (pd.getWriteMethod() != null) { this.mappedFields.put(lowerCaseName(pd.getName()), pd); String underscoredName = underscoreName(pd.getName()); if (!lowerCaseName(pd.getName()).equals(underscoredName)) { this.mappedFields.put(underscoredName, pd); } this.mappedProperties.add(pd.getName()); } } }
public BeanPropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) { super(propertyName, calculateMatches(propertyName, BeanUtils.getPropertyDescriptors(beanClass), maxDistance)); }
/** * Find a JavaBeans {@code PropertyDescriptor} for the given method, * with the method either being the read method or the write method for * that bean property. * @param method the method to find a corresponding PropertyDescriptor for * @param clazz the (most specific) class to introspect for descriptors * @return the corresponding PropertyDescriptor, or {@code null} if none * @throws BeansException if PropertyDescriptor lookup fails * @since 3.2.13 */ @Nullable public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException { Assert.notNull(method, "Method must not be null"); PropertyDescriptor[] pds = getPropertyDescriptors(clazz); for (PropertyDescriptor pd : pds) { if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) { return pd; } } return null; }
/** * Create a new PropertyMatches instance for the given property. */ private PropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) { this.propertyName = propertyName; this.possibleMatches = calculateMatches(BeanUtils.getPropertyDescriptors(beanClass), maxDistance); }
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
@Test public void testBeanPropertyIsArray() { PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(ContainerBean.class); for (PropertyDescriptor descriptor : descriptors) { if ("containedBeans".equals(descriptor.getName())) { assertTrue("Property should be an array", descriptor.getPropertyType().isArray()); assertEquals(descriptor.getPropertyType().getComponentType(), ContainedBean.class); } } }
PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null);
@Test public void testSPR6063() { PropertyDescriptor[] descrs = BeanUtils.getPropertyDescriptors(Bean.class); PropertyDescriptor keyDescr = BeanUtils.getPropertyDescriptor(Bean.class, "value"); assertEquals(String.class, keyDescr.getPropertyType()); for (PropertyDescriptor propertyDescriptor : descrs) { if (propertyDescriptor.getName().equals(keyDescr.getName())) { assertEquals(propertyDescriptor.getName() + " has unexpected type", keyDescr.getPropertyType(), propertyDescriptor.getPropertyType()); } } }
@Test public void testGetPropertyDescriptors() throws Exception { PropertyDescriptor[] actual = Introspector.getBeanInfo(TestBean.class).getPropertyDescriptors(); PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(TestBean.class); assertNotNull("Descriptors should not be null", descriptors); assertEquals("Invalid number of descriptors returned", actual.length, descriptors.length); }
@Test public void clearClassLoaderForSystemClassLoader() throws Exception { BeanUtils.getPropertyDescriptors(ArrayList.class); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)); CachedIntrospectionResults.clearClassLoader(ArrayList.class.getClassLoader()); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)); }
PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean)); List<ModelMBeanAttributeInfo> infos = new ArrayList<>();
PropertyDescriptor[] props = BeanUtils.getPropertyDescriptors(getClassToExpose(managedBean)); List<ModelMBeanAttributeInfo> infos = new ArrayList<>();
/** * Create a new PropertyMatches instance for the given property. */ private PropertyMatches(String propertyName, Class beanClass, int maxDistance) { this.propertyName = propertyName; this.possibleMatches = calculateMatches(BeanUtils.getPropertyDescriptors(beanClass), maxDistance); }
/** * Find a JavaBeans <code>PropertyDescriptor</code> for the given method, * with the method either being the read method or the write method for * that bean property. * @param method the method to find a corresponding PropertyDescriptor for * @return the corresponding PropertyDescriptor, or <code>null</code> if none * @throws BeansException if PropertyDescriptor lookup fails */ public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException { Assert.notNull(method, "Method must not be null"); PropertyDescriptor[] pds = getPropertyDescriptors(method.getDeclaringClass()); for (PropertyDescriptor pd : pds) { if (method.equals(pd.getReadMethod()) || method.equals(pd.getWriteMethod())) { return pd; } } return null; }
/** * Take a {@link Class} and find all properties that are NOT to be ignored, and return them as a {@link Stream}. * * @param clazz * @return */ private static Stream<PropertyDescriptor> getPropertyDescriptors(Class<?> clazz) { return Arrays.stream(BeanUtils.getPropertyDescriptors(clazz)) .filter(descriptor -> !FIELDS_TO_IGNORE.contains(descriptor.getName())) .filter(descriptor -> !descriptorToBeIgnoredByJackson(clazz, descriptor)) .filter(descriptor -> !toBeIgnoredByJackson(clazz, descriptor.getName())) .filter(descriptor -> !readerIsNotToBeIgnoredByJackson(descriptor)); }
/** * Initialize the mapping metadata for the given class. * * @param mappedClass the mapped class. */ protected void initialize() { this.mappedFields = new HashMap<String, PropertyDescriptor>(); PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass); if (checkProperties) { mappedProperties = new HashSet<String>(); } for (int i = 0; i < pds.length; i++) { PropertyDescriptor pd = pds[i]; if (pd.getWriteMethod() != null) { if (checkProperties) { this.mappedProperties.add(pd.getName()); } this.mappedFields.put(pd.getName().toLowerCase(), pd); for (String underscoredName : underscoreName(pd.getName())) { if (underscoredName != null && !pd.getName().toLowerCase().equals(underscoredName)) { this.mappedFields.put(underscoredName, pd); } } } } }
for (PropertyDescriptor propertyDescriptor : BeanUtils.getPropertyDescriptors(clazz)) {