@SneakyThrows @Test public void testGetProperties() { Map<String, BeanProperty> properties = ClassUtil.getProperties(B.class); log.info("Properties.keySet():" + properties.keySet()); String[] exp = {"fieldA1", "fieldA2", "fieldA3", "fieldA4", "fieldB1", "fieldB2", "fieldB3", "fieldB4", "fieldB5", "fieldB6"}; assertArrayEquals(exp, properties.keySet().toArray()); BeanProperty prop = properties.get("fieldB6"); assertEquals("fieldB6", prop.getName()); B b = new B(); prop.set(b, true); assertEquals(true, prop.get(b)); assertFalse(prop.isImmutable(false)); assertTrue(prop.isReadable(false)); assertEquals(Boolean.TYPE, prop.getType()); assertEquals(Boolean.TYPE, prop.getGenericType()); assertEquals(B.class.getMethod("setFieldB6", new Class[]{Boolean.TYPE}), prop.getSetter()); assertEquals(B.class.getMethod("isFieldB6", new Class[0]), prop.getGetter()); assertTrue(prop.isTransient()); assertFalse(prop.isFieldAccessible(false)); assertNotNull("Transient is annotated", prop.getAnnotation(Transient.class)); prop = properties.get("fieldB2"); prop.set(b, "str"); assertNull(prop.getSetter()); assertNull(prop.getGetter()); assertNotNull(prop.getField()); assertEquals("str", prop.get(b)); }
public static Map<String, BeanProperty> getProperties(Class<?> cls) { Map<String, BeanProperty> result = beanPropertyCache.get(cls); if (result == null) { synchronized(beanPropertyCache) { result = _getProperties(cls); beanPropertyCache.put(cls, result); } } return result; }
ClassUtil { public static Map<String, BeanProperty> getProperties(Class<?> cls) { Map<String, BeanProperty> result = beanPropertyCache.get(cls); if (result == null) { synchronized(beanPropertyCache) { result = _getProperties(cls); beanPropertyCache.put(cls, result); } } return result; } }
ClassUtil { public static Map<String, BeanProperty> getProperties(Class<?> cls) { Map<String, BeanProperty> result = beanPropertyCache.get(cls); if (result == null) { synchronized(beanPropertyCache) { result = _getProperties(cls); beanPropertyCache.put(cls, result); } } return result; }  }
ClassUtil { public static Map<String, BeanProperty> getProperties(Class<?> cls) { Map<String, BeanProperty> result = beanPropertyCache.get(cls); if (result == null) { synchronized(beanPropertyCache) { result = _getProperties(cls); beanPropertyCache.put(cls, result); } } return result; }  @Deprecated //Used only for testing, don't use in production code @SneakyThrows static void setStaticPrivateField(String className, String fieldName, Object value); @Deprecated //Used only for testing, don't use in production code static void setPrivateField(Object obj, String fieldName, Object value); @Deprecated //Used only for testing, don't use in production code @SneakyThrows static void setPrivateField(Class<?> cls, Object obj, String fieldName, Object value); static Field getDeclaredField(Class<?> cls, String name); static Map<String, BeanProperty> getProperties(Class<?> cls); static Object getObjectByPath(String path); static Object getObjectByPath(Class<?> cls, Object obj, List<String> relativePath); static Object getObjectProperty(Class<?> cls, Object obj, String propertyName); static Class<?> getGenericClass(Type type); static Type[] getGenericTypeActualParams(Type type); static Type[] getGenericTypeActualParamsForInterface(Type type, Class<?> intf); static List<Class<?>> getAllInterface(Class<?> cls); static Class<?> findInterface(Class<?> cls, Class<?> itf); static Field[] getAllFields(Class<?> cls); static Method[] getAllMethods(Class<?> cls); static T stringToEnum(Class<T> cls, String str); @SuppressWarnings({ "unchecked", "rawtypes" }) static T stringToSimpleObject(String str, Class<T> cls, BeanConvertContext ctx); static boolean isSimpleType(Class<?> cls); static Object objectToSimpleType(Object obj, Class<?> cls); static Type getType(String typeName); static StackTraceElement findCallerStackTrace(Class<?> calleeClass); }
ClassUtil { public static Map<String, BeanProperty> getProperties(Class<?> cls) { Map<String, BeanProperty> result = beanPropertyCache.get(cls); if (result == null) { synchronized(beanPropertyCache) { result = _getProperties(cls); beanPropertyCache.put(cls, result); } } return result; }  @Deprecated //Used only for testing, don't use in production code @SneakyThrows static void setStaticPrivateField(String className, String fieldName, Object value); @Deprecated //Used only for testing, don't use in production code static void setPrivateField(Object obj, String fieldName, Object value); @Deprecated //Used only for testing, don't use in production code @SneakyThrows static void setPrivateField(Class<?> cls, Object obj, String fieldName, Object value); static Field getDeclaredField(Class<?> cls, String name); static Map<String, BeanProperty> getProperties(Class<?> cls); static Object getObjectByPath(String path); static Object getObjectByPath(Class<?> cls, Object obj, List<String> relativePath); static Object getObjectProperty(Class<?> cls, Object obj, String propertyName); static Class<?> getGenericClass(Type type); static Type[] getGenericTypeActualParams(Type type); static Type[] getGenericTypeActualParamsForInterface(Type type, Class<?> intf); static List<Class<?>> getAllInterface(Class<?> cls); static Class<?> findInterface(Class<?> cls, Class<?> itf); static Field[] getAllFields(Class<?> cls); static Method[] getAllMethods(Class<?> cls); static T stringToEnum(Class<T> cls, String str); @SuppressWarnings({ "unchecked", "rawtypes" }) static T stringToSimpleObject(String str, Class<T> cls, BeanConvertContext ctx); static boolean isSimpleType(Class<?> cls); static Object objectToSimpleType(Object obj, Class<?> cls); static Type getType(String typeName); static StackTraceElement findCallerStackTrace(Class<?> calleeClass); static final Type[] EMPTY_TYPE_ARRAY; static final Map<String, Class<?>> PRIMITIVE_TYPE_MAP; }