/** * Added for apache commons beanutils compatibility, * you should probably use {@link #convert(Object, Class)}<br/> * Convert the string value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value the string value to be converted * @param type any class type that you want to try to convert the object to * @return the converted value * @throws UnsupportedOperationException if the conversion cannot be completed */ public Object convertString(String value, Class<?> type) { Object convert = null; try { convert = convert(value, type); } catch (UnsupportedOperationException e) { convert = value; } return convert; }
/** * Added for apache commons beanutils compatibility, * you should probably use {@link #convert(Object, Class)}<br/> * Convert the string value to an object of the specified class (if * possible). Otherwise, return a String representation of the value. * * @param value the string value to be converted * @param type any class type that you want to try to convert the object to * @return the converted value * @throws UnsupportedOperationException if the conversion cannot be completed */ public Object convertString(String value, Class<?> type) { Object convert = null; try { convert = convert(value, type); } catch (UnsupportedOperationException e) { convert = value; } 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; }
/** * 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; }
/** * Get the value of a field on an object as a specific type, * name can be nested, indexed, or mapped * @param obj any object * @param name the name of a field on this object * @param asType the type to return the value as (converts as needed) * @return the value in the field as the type requested * @throws FieldnameNotFoundException if this field name is invalid for this object * @throws FieldGetValueException if the field is not readable or not visible * @throws UnsupportedOperationException if the value cannot be converted to the type requested * @throws IllegalArgumentException if there is a failure getting the value */ public <T> T getFieldValue(Object obj, String name, Class<T> asType) { Object o = getFieldValue(obj, name); T value = getConversionUtils().convert(o, asType); return value; }
/** * Get the value of a field on an object as a specific type, * name can be nested, indexed, or mapped * @param obj any object * @param name the name of a field on this object * @param asType the type to return the value as (converts as needed) * @return the value in the field as the type requested * @throws FieldnameNotFoundException if this field name is invalid for this object * @throws FieldGetValueException if the field is not readable or not visible * @throws UnsupportedOperationException if the value cannot be converted to the type requested * @throws IllegalArgumentException if there is a failure getting the value */ public <T> T getFieldValue(Object obj, String name, Class<T> asType) { Object o = getFieldValue(obj, name); T value = getConversionUtils().convert(o, asType); return value; }
/** * 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; }
for (int i = 0; i < length; i++) { Object object = Array.get(toConvert, i); object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); int i = 0; for (Object object : collection) { object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); i++; int i = 0; for (Object object : map.values()) { object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); i++; convert = (T) Array.newInstance(componentType, parts.length); for (int i = 0; i < parts.length; i++) { Object object = getConversionUtils().convert(parts[i].trim(), componentType); // convert each value Array.set(convert, i, object); Object object = getConversionUtils().convert(toConvert, componentType); // convert each value Array.set(convert, 0, object);
/** * 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; }
/** * This helper method will convert the incoming data if it needs to be * converted for the given column, otherwise it will do nothing to the value * @param namesRecord the names record for the persistent class * @param column the name of the column this value is associated with * @param value the value to convert * @return the converted value or the original value if no conversion needed */ public static Object convertColumn(NamesRecord namesRecord, String column, Object value) { if (namesRecord != null && column != null) { try { Class<?> convertType = namesRecord.getTypeForColumn(column); if (convertType != null) { value = ConversionUtils.getInstance().convert(value, convertType); } } catch (Exception e) { // nothing to do but continue on } } return value; }
for (int i = 0; i < length; i++) { Object object = Array.get(toConvert, i); object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); int i = 0; for (Object object : collection) { object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); i++; int i = 0; for (Object object : map.values()) { object = getConversionUtils().convert(object, componentType); // convert each value Array.set(convert, i, object); i++; convert = (T) Array.newInstance(componentType, parts.length); for (int i = 0; i < parts.length; i++) { Object object = getConversionUtils().convert(parts[i].trim(), componentType); // convert each value Array.set(convert, i, object); Object object = getConversionUtils().convert(toConvert, componentType); // convert each value Array.set(convert, 0, object);
convert = getConversionUtils().convert(toConvert, toType); return convert;
convert = getConversionUtils().convert(toConvert, toType); return convert;
value = getConversionUtils().convert(value, field.getType()); field.set(obj, value); } catch (Exception e) {
orig = getConversionUtils().convert(orig, destClass); origClass = destClass; } catch (UnsupportedOperationException e) {
orig = getConversionUtils().convert(orig, destClass); origClass = destClass; } catch (UnsupportedOperationException e) {
value = getConversionUtils().convert(value, field.getType()); field.set(obj, value); } catch (Exception e) {
value = getConversionUtils().convert(value, type);
value = getConversionUtils().convert(value, type);