Class JSONValueType
java.lang.Object
com.github.nedelis.jc4j.jsonvalue.JSONValueType
This class allows you to convert any value from a json to a java value;
You also can register your own java value types by using
register(String, IJSONValueType)
All registered types will be stored in the TYPES; If you need to get definite
IJSONValueType you can use saved constants of them
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IJSONValueType<Boolean>static final IJSONValueType<Double>static final IJSONValueType<Integer>static final IJSONValueType<ArrayList<JSONValue>>static final IJSONValueType<HashMap<String,JSONValue>> static final IJSONValueType<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> IJSONValueType<T>register(String name, IJSONValueType<T> type) Registers a new IJSONValueType (puts it inTYPESand returns it)static <T> TtoJavaValue(Object jsonValue, @NotNull IJSONValueType<T> valueType) static <T> TtoJavaValue(Object jsonValue, T def) This method tries to find correct JSONValueType for "T def" and converts given value to java value; If it can't find correct JSONValueType for "T def", then it'll issue a warning and return given default valuestatic <T> TtoJavaValue(Object jsonValue, T def, @NotNull IJSONValueType<T> valueType)
-
Field Details
-
STR
-
INT
-
DOUBLE
-
BOOL
-
JS_VAL_LIST
-
JS_VAL_MAP
-
-
Constructor Details
-
JSONValueType
public JSONValueType()
-
-
Method Details
-
register
Registers a new IJSONValueType (puts it inTYPESand returns it)- Type Parameters:
T- specifies the type of returned IJSONValueType- Parameters:
name- name that will be associated with new IJSONValueTypetype- IJSONValueType that will be registered- Returns:
- provided IJSONValueType
-
toJavaValue
This method tries to find correct JSONValueType for "T def" and converts given value to java value; If it can't find correct JSONValueType for "T def", then it'll issue a warning and return given default value- Type Parameters:
T- specifies which type the java value will be- Parameters:
jsonValue- value to convertdef- default value that will be returned if conversion failed; specifies the "T"- Returns:
- converted json value
-
toJavaValue
-
toJavaValue
public static <T> T toJavaValue(Object jsonValue, T def, @NotNull @NotNull IJSONValueType<T> valueType)
-