public final class FieldParser extends Object
String o1 = String.valueOf(1); ; Integer i = FieldParser.convert(o1, Integer.class); System.out.println(i); // 1
| Constructor and Description |
|---|
FieldParser() |
| Modifier and Type | Method and Description |
|---|---|
static String |
booleanToString(Boolean value)
Converts Boolean to String.
|
static <T> T |
convert(Object from,
Class<T> to)
Convert the given object value to the given class.
|
static String |
integerToString(Integer value)
Converts Integer to String.
|
static <T> void |
setEmptyValue(String strValue,
Field field,
T obj)
Sets the empty/null value if field is allowed to be set empty.
|
static Boolean |
stringToBoolean(String value)
Converts String to Boolean.
|
static Double |
stringToDouble(String val)
Converts String to Double.
|
static Float |
stringToFloat(String val)
Converts String to float.
|
static Integer |
stringToInteger(String val)
Converts String to Integer.
|
static <T> List<T> |
stringToList(String val,
Class<T> type)
Converts comma separated string to List.
|
static Long |
stringToLong(String val)
Converts String to Long.
|
static <T> Set<T> |
stringToSet(String val,
Class<T> type)
Converts comma separated string to Set.
|
static <T> void |
update(Map<String,String> properties,
T obj)
Update given Object attribute by reading it from provided map properties.
|
static Object |
value(String strValue,
Field field)
Converts value as per appropriate DataType of the field.
|
public static <T> T convert(Object from, Class<T> to)
from - The object value to be converted.to - The type class which the given object should be converted to.UnsupportedOperationException - If no suitable converter can be found.RuntimeException - If conversion failed somehow. This can be caused by at least an ExceptionInInitializerError,
IllegalAccessException or InvocationTargetException.public static <T> void update(Map<String,String> properties, T obj) throws IllegalArgumentException
properties - which key-value pair of properties to assign those values to given objectobj - object which needs to be updatedIllegalArgumentException - if the properties key-value contains incorrect value typepublic static Object value(String strValue, Field field)
strValue - : string value of the objectfield - : field of the attributepublic static <T> void setEmptyValue(String strValue, Field field, T obj) throws IllegalArgumentException, IllegalAccessException
strValue - field - obj - IllegalArgumentExceptionIllegalAccessExceptionpublic static Integer stringToInteger(String val)
val - The String to be converted.public static Long stringToLong(String val)
val - The String to be converted.public static Double stringToDouble(String val)
val - The String to be converted.public static Float stringToFloat(String val)
val - The String to be converted.public static <T> List<T> stringToList(String val, Class<T> type)
T - type of listval - comma separated values.<T>.public static <T> Set<T> stringToSet(String val, Class<T> type)
T - type of setval - comma separated values.<T>.public static String integerToString(Integer value)
value - The Integer to be converted.public static String booleanToString(Boolean value)
value - The Boolean to be converted.Copyright © 2017–2022 Apache Software Foundation. All rights reserved.