/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Converts an object to any other object if possible * @see ConversionUtils#convert(Object, Class) * * @param <T> * @param object any object * @param type any class type that you want to try to convert the object to * @return the converted value (allows null to pass through except in the case of primitives which become the primitive default) * @throws UnsupportedOperationException if the conversion cannot be completed */ public <T> T convert(Object object, Class<T> type) { T convert = getConversionUtils().convert(object, type); return convert; }
/** * Converts an object to any other object if possible * @see ConversionUtils#convert(Object, Class) * * @param <T> * @param object any object * @param type any class type that you want to try to convert the object to * @return the converted value (allows null to pass through except in the case of primitives which become the primitive default) * @throws UnsupportedOperationException if the conversion cannot be completed */ public <T> T convert(Object object, Class<T> type) { T convert = getConversionUtils().convert(object, type); return convert; }
@Override public String toString() { return "Reflect::c="+ReflectUtils.timesCreated+":s="+singleton+":" + getClassDataCacher() + ":" + getFieldUtils() + ":" + getConversionUtils(); }
@Override public String toString() { return "Reflect::c="+ReflectUtils.timesCreated+":s="+singleton+":" + getClassDataCacher() + ":" + getFieldUtils() + ":" + getConversionUtils(); }
/** * Get the string value of a field or getter method from an object allowing an annotation to override<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 * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the string value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public String getFieldValueAsString(Object object, String fieldName, Class<? extends Annotation> annotationClass) { String sValue = null; Object value = getFieldValue(object, fieldName, annotationClass); if (value != null) { sValue = getConversionUtils().convert(value, String.class); //value.toString(); } return sValue; }
/** * Get the string value of a field or getter method from an object allowing an annotation to override<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 * @param annotationClass if the annotation class is set then we will attempt to get the value from the annotated field or getter method first * @return the string value of the field OR null if the value is null * @throws FieldnameNotFoundException if this fieldName does not exist on the object and no annotation was found * @throws IllegalArgumentException if a failure occurs while getting the field value */ public String getFieldValueAsString(Object object, String fieldName, Class<? extends Annotation> annotationClass) { String sValue = null; Object value = getFieldValue(object, fieldName, annotationClass); if (value != null) { sValue = getConversionUtils().convert(value, String.class); //value.toString(); } return sValue; }