/** * Analyze an object and produce an object which contains information about it and its fields * @param obj any object * @return the ClassFields analysis object which contains the information about this object class * @throws IllegalArgumentException if obj is null */ @SuppressWarnings("unchecked") public <T> ClassFields<T> analyzeObject(Object obj) { if (obj == null) { throw new IllegalArgumentException("obj cannot be null"); } if (Class.class.equals(obj)) { // this is a class so we should pass it over to the other method return analyzeClass((Class)obj); } Class<T> cls = (Class<T>) obj.getClass(); return analyzeClass(cls); }
/** * Analyze an object and produce an object which contains information about it and its fields * @param obj any object * @return the ClassFields analysis object which contains the information about this object class * @throws IllegalArgumentException if obj is null */ @SuppressWarnings("unchecked") public <T> ClassFields<T> analyzeObject(Object obj) { if (obj == null) { throw new IllegalArgumentException("obj cannot be null"); } if (Class.class.equals(obj)) { // this is a class so we should pass it over to the other method return analyzeClass((Class)obj); } Class<T> cls = (Class<T>) obj.getClass(); return analyzeClass(cls); }
/** * Analyze a class and produce an object which contains information about it and its fields * @param <T> * @param beanClass any object class * @return the ClassFields analysis object which contains the information about this object class * @throws IllegalArgumentException if class is null or primitive */ public <T> ClassFields<T> analyzeClass(Class<T> beanClass) { return getFieldUtils().analyzeClass(beanClass); }
/** * Get the names of all fields in a class * @param cls any class * @return a list of the field names */ public <T> List<String> getFieldNames(Class<T> cls) { ClassFields<T> cf = analyzeClass(cls); return cf.getFieldNames(); }
/** * Analyze a class and produce an object which contains information about it and its fields * @param <T> * @param beanClass any object class * @return the ClassFields analysis object which contains the information about this object class * @throws IllegalArgumentException if class is null or primitive */ public <T> ClassFields<T> analyzeClass(Class<T> beanClass) { return getFieldUtils().analyzeClass(beanClass); }
/** * Get the names of all fields in a class * @param cls any class * @return a list of the field names */ public <T> List<String> getFieldNames(Class<T> cls) { ClassFields<T> cf = analyzeClass(cls); return cf.getFieldNames(); }
/** * Get the types of the fields of a specific class type <br/> * returns the method names as fields (without the "get"/"is" part and camelCased) * @param type any class * @param filter (optional) indicates the fields to return the types for, can be null for defaults * @return a map of field name -> class type */ public Map<String, Class<?>> getFieldTypes(Class<?> type, FieldsFilter filter) { ClassFields<?> cf = analyzeClass(type, findFieldFindMode(filter)); Map<String, Class<?>> types = cf.getFieldTypes(filter); return types; }
/** * Find the getter field on a class which has the given annotation * @param elementClass any class * @param annotationClass the annotation type which is expected to be on the field * @return the name of the field or null if no fields are found with the indicated annotation * @throws IllegalArgumentException if the annotation class is null */ public String getFieldNameWithAnnotation(Class<?> elementClass, Class<? extends Annotation> annotationClass) { String fieldName; if (annotationClass == null) { throw new IllegalArgumentException("the annotationClass must not be null"); } ClassFields<?> cf = getFieldUtils().analyzeClass(elementClass); fieldName = cf.getFieldNameByAnnotation(annotationClass); return fieldName; }
/** * Get the types of the fields of a specific class type <br/> * returns the method names as fields (without the "get"/"is" part and camelCased) * @param type any class * @param filter (optional) indicates the fields to return the types for, can be null for defaults * @return a map of field name -> class type */ public Map<String, Class<?>> getFieldTypes(Class<?> type, FieldsFilter filter) { ClassFields<?> cf = analyzeClass(type, findFieldFindMode(filter)); Map<String, Class<?>> types = cf.getFieldTypes(filter); return types; }
/** * Find the getter field on a class which has the given annotation * @param elementClass any class * @param annotationClass the annotation type which is expected to be on the field * @return the name of the field or null if no fields are found with the indicated annotation * @throws IllegalArgumentException if the annotation class is null */ public String getFieldNameWithAnnotation(Class<?> elementClass, Class<? extends Annotation> annotationClass) { String fieldName; if (annotationClass == null) { throw new IllegalArgumentException("the annotationClass must not be null"); } ClassFields<?> cf = getFieldUtils().analyzeClass(elementClass); fieldName = cf.getFieldNameByAnnotation(annotationClass); return fieldName; }
public Enum convertInterface(Object value, Class<? extends Enum> implementationType) { Enum convert = null; String name = value.toString(); // can only deal with strings // now we try to find the enum field in this enum class ClassFields<Enum> cf = (ClassFields<Enum>) getFieldUtils().analyzeClass(implementationType); List<Enum> enumConstants = cf.getClassData().getEnumConstants(); for (Enum e : enumConstants) { if (e.name().equals(name)) { // found the matching enum convert = e; break; } } if (convert == null) { throw new UnsupportedOperationException("Failure attempting to create enum for name ("+name+") in ("+implementationType+")"); } return convert; }
public <T> List<String> getFieldNames(Class<T> cls, FieldsFilter filter) { ClassFields<T> cf = analyzeClass(cls, findFieldFindMode(filter)); return cf.getFieldNames(); }
public <T> List<String> getFieldNames(Class<T> cls, FieldsFilter filter) { ClassFields<T> cf = analyzeClass(cls, findFieldFindMode(filter)); return cf.getFieldNames(); }
public Enum convertInterface(Object value, Class<? extends Enum> implementationType) { Enum convert = null; String name = value.toString(); // can only deal with strings // now we try to find the enum field in this enum class ClassFields<Enum> cf = (ClassFields<Enum>) getFieldUtils().analyzeClass(implementationType); List<Enum> enumConstants = cf.getClassData().getEnumConstants(); for (Enum e : enumConstants) { if (e.name().equals(name)) { // found the matching enum convert = e; break; } } if (convert == null) { throw new UnsupportedOperationException("Failure attempting to create enum for name ("+name+") in ("+implementationType+")"); } return convert; }
} else { ClassFields<?> cf = analyzeClass(type); nestedClass = cf.getFieldType(name); } else { ClassFields<?> cf = analyzeClass(type); try { fieldType = cf.getFieldType(targetName);
} else { ClassFields<?> cf = analyzeClass(type); nestedClass = cf.getFieldType(name); } else { ClassFields<?> cf = analyzeClass(type); try { fieldType = cf.getFieldType(targetName);
ClassFields<?> cf = getFieldUtils().analyzeClass(beanClass); Map<String, Class<?>> types = cf.getFieldTypes(filter); for (String name : types.keySet()) {
ClassFields<?> cf = getFieldUtils().analyzeClass(beanClass); Map<String, Class<?>> types = cf.getFieldTypes(filter); for (String name : types.keySet()) {