/** * 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); }
/** * 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; }
/** * 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); }
/** * Get a map of all fieldName -> value and all getterMethodName -> value without the word "get" * where the method takes no arguments, in other words, all values available from an object (readable values) * @param object any object * @param filter (optional) indicates the fields to return the values for, can be null for defaults * @param includeClassField if true then the value from the "getClass()" method is returned as part of the * set of object values with a type of {@link Class} and a field name of "class" * @return a map of name -> value * @throws IllegalArgumentException if failures occur */ public Map<String, Object> getObjectValues(Object object, FieldsFilter filter, boolean includeClassField) { return getFieldUtils().getFieldValues(object, filter, includeClassField); }
/** * 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 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; }
/** * 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); }
/** * 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); }
/** * Get a map of all fieldName -> value and all getterMethodName -> value without the word "get" * where the method takes no arguments, in other words, all values available from an object (readable values) * @param object any object * @param filter (optional) indicates the fields to return the values for, can be null for defaults * @param includeClassField if true then the value from the "getClass()" method is returned as part of the * set of object values with a type of {@link Class} and a field name of "class" * @return a map of name -> value * @throws IllegalArgumentException if failures occur */ public Map<String, Object> getObjectValues(Object object, FieldsFilter filter, boolean includeClassField) { return getFieldUtils().getFieldValues(object, filter, includeClassField); }
/** * Get the value of a field or property (getter method) from an object<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @throws FieldnameNotFoundException if this fieldName does not exist on the object * @throws IllegalArgumentException if a failure occurs while getting the field value */ public Object getFieldValue(Object object, String fieldName) { return getFieldUtils().getFieldValue(object, fieldName); }
/** * Get the value of a field or property (getter method) from an object<br/> * Getting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to get the value of or the getter method without the "get" and lowercase first char * @throws FieldnameNotFoundException if this fieldName does not exist on the object * @throws IllegalArgumentException if a failure occurs while getting the field value */ public Object getFieldValue(Object object, String fieldName) { return getFieldUtils().getFieldValue(object, fieldName); }
/** * Set the value on the object field or setter method, will convert if needed<br/> * Setting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to set the value of or the setter method without the "set" and lowercase first char * @param value the value to set on this field, must match the type in the object (will not attempt to covert) * @throws FieldnameNotFoundException if the fieldName could not be found in this object * @throws UnsupportedOperationException if the value could not be converted to the field type * @throws IllegalArgumentException if the params are null or other failures occur setting the value */ public void setFieldValue(Object object, String fieldName, Object value) { getFieldUtils().setFieldValue(object, fieldName, value); }
/** * Set the value on the object field or setter method, will convert if needed<br/> * Setting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to set the value of or the setter method without the "set" and lowercase first char * @param value the value to set on this field, must match the type in the object (will not attempt to covert) * @throws FieldnameNotFoundException if the fieldName could not be found in this object * @throws UnsupportedOperationException if the value could not be converted to the field type * @throws IllegalArgumentException if the params are null or other failures occur setting the value */ public void setFieldValue(Object object, String fieldName, Object value) { getFieldUtils().setFieldValue(object, fieldName, value); }
/** * Sets a value on the field of an object and will attempt to convert the property if configured to do so<br/> * Setting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to set the value of or the setter method without the "set" and lowercase first char * @param value the value to set on this field, does not have to match the type in the object, * the type will be determined and then we will attempt to convert this value to the type in the field * @param autoConvert if true then automatically try to convert the value to the type of the field being set, * otherwise only set the field if the value matches the type * @throws FieldnameNotFoundException if the fieldName could not be found in this object * @throws IllegalArgumentException if the value type does not match the field type or the type could not be converted to the field type * @throws UnsupportedOperationException if the value could not be converted to the field type */ public void setFieldValue(Object object, String fieldName, Object value, boolean autoConvert) { getFieldUtils().setFieldValue(object, fieldName, value, autoConvert); }
/** * Sets a value on the field of an object and will attempt to convert the property if configured to do so<br/> * Setting fields supports simple, nested, indexed, and mapped values:<br/> * <b>Simple:</b> Get/set a field in a bean (or map), Example: "title", "id"<br/> * <b>Nested:</b> Get/set a field in a bean which is contained in another bean, Example: "someBean.title", "someBean.id"<br/> * <b>Indexed:</b> Get/set a list/array item by index in a bean, Example: "myList[1]", "anArray[2]"<br/> * <b>Mapped:</b> Get/set a map entry by key in a bean, Example: "myMap(key)", "someMap(thing)"<br/> * * @param object any object * @param fieldName the name of the field (property) to set the value of or the setter method without the "set" and lowercase first char * @param value the value to set on this field, does not have to match the type in the object, * the type will be determined and then we will attempt to convert this value to the type in the field * @param autoConvert if true then automatically try to convert the value to the type of the field being set, * otherwise only set the field if the value matches the type * @throws FieldnameNotFoundException if the fieldName could not be found in this object * @throws IllegalArgumentException if the value type does not match the field type or the type could not be converted to the field type * @throws UnsupportedOperationException if the value could not be converted to the field type */ public void setFieldValue(Object object, String fieldName, Object value, boolean autoConvert) { getFieldUtils().setFieldValue(object, fieldName, value, autoConvert); }
/** * 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; }
@Override public String toString() { return "Reflect::c="+ReflectUtils.timesCreated+":s="+singleton+":" + getClassDataCacher() + ":" + getFieldUtils() + ":" + getConversionUtils(); }
/** * 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; }
@Override public String toString() { return "Reflect::c="+ReflectUtils.timesCreated+":s="+singleton+":" + getClassDataCacher() + ":" + getFieldUtils() + ":" + getConversionUtils(); }