/** * This method returns true if the given annotation is present on the given field. * * @param fieldClass * @param fieldName * @param annotation * @return true if the given annotation is present */ public static boolean isAnnotationPresent(Class<?> fieldClass, String fieldName, Class<? extends Annotation> annotation) { ClassFields<?> classFields = ClassDataCacher.getInstance().getClassFields(fieldClass); try { return classFields.getFieldAnnotation(annotation, fieldName) != null; } catch (FieldnameNotFoundException e) { return false; } }
/** * This method return all the fields (including private) from the given class and its super * classes. * * @param fieldClass Class * @return List<Field> * @should return all fields include private and super classes */ public static List<Field> getAllFields(Class<?> fieldClass) { List<Field> fields = ClassDataCacher.getInstance().getClassData(fieldClass).getFields(); return new ArrayList<>(fields); }
/** * Set the option to include the "class" field when reflecting over objects, * the default for this is false (do not include) * @param includeClassField if true then include the value from the "getClass()" method as "class" when encoding beans and maps */ public void setIncludeClassField(boolean includeClassField) { getClassDataCacher().setIncludeClassField(includeClassField); }
/** * 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; }
/** * Analyze a class and produce an object which contains information about it and its fields * @param <T> * @param cls any 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> cls) { ClassFields<T> cf = getClassDataCacher().getClassFields(cls); return cf; }
@Override public boolean isSettable() { boolean settable = false; if (getIndexSetter() != null || super.isSettable()) { settable = true; } return settable; } }
/** * 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(); }
/** * Add a converter to the default set which will convert objects to the supplied type * @param type the type this converter will convert objects to * @param converter the converter */ public void addConverter(Class<?> type, Converter<?> converter) { getConversionUtils().addConverter(type, converter); }
/** * 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 type of a field from a class * @param type any class * @param fieldName the name of the field (property) or a getter method converted to a field name * @return the type of object stored in the field * @throws FieldnameNotFoundException if the fieldName could not be found in this object */ public Class<?> getFieldType(Class<?> type, String fieldName) { return getFieldUtils().getFieldType(type, fieldName); }
@Override public boolean isGettable() { boolean gettable = false; if (getMapGetter() != null || super.isGettable()) { gettable = true; } return gettable; } @Override
/** * Set the cache to be used for holding the reflection data, * this allows control over where the reflection caches are stored, * this should store the data in a way that it will not hold open the classloader the class comes from <br/> * Note that you can set this to a map implementation which does not store anything to disable caching if you like * * @param reflectionCache a cache for holding class cache data (implements map), null to use the default internal cache */ @SuppressWarnings("unchecked") public void setReflectionCache(Map<Class<?>, ClassFields> reflectionCache) { getClassDataCacher().setReflectionCache(reflectionCache); }
/** * Set the field name path resolver to use * @param resolver the field path name resolver to use when resolving EL style paths, null for default * @see FieldUtils#setResolver(Resolver) */ public void setResolver(Resolver resolver) { getFieldUtils().setResolver(resolver); }
/** * Set the object converters to add to the default converters * @param converters a map of converters to add to the default set, null to just use the default set */ public void setConverters(Map<Class<?>, Converter<?>> converters) { getConversionUtils().setConverters(converters); }
@Override public boolean isSettable() { boolean settable = false; if (getMapSetter() != null || super.isSettable()) { settable = true; } return settable; } }
/** * Get the types of the fields of a specific class type, * returns the method names 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 */ @SuppressWarnings("SameParameterValue") public Map<String, Class<?>> getFieldTypes(Class<?> type, FieldsFilter filter) { Map<String, Class<?>> types = getFieldUtils().getFieldTypes(type, filter); return types; }
@Override public boolean isGettable() { boolean gettable = false; if (getIndexGetter() != null || super.isGettable()) { gettable = true; } return gettable; } @Override
/** * @param name the fieldName * @return the type of this field * @throws FieldnameNotFoundException if this fieldName is invalid */ public Class<?> getFieldType(String name) { ClassProperty cp = getAnyPropertyOrFail(name); Class<?> type = cp.getType(); return type; }
/** * 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; }
@Override public boolean isSettable() { boolean settable = false; if (getIndexSetter() != null || super.isSettable()) { settable = true; } return settable; } }