Package com.startapp.json
Class JsonParser
- java.lang.Object
-
- com.startapp.json.JsonParser
-
public class JsonParser extends java.lang.ObjectContains static methods to parse and to serialize objects.- See Also:
TypeInfo,TypeClassInfo,TypeParser
-
-
Constructor Summary
Constructors Constructor Description JsonParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TfromJson(java.lang.String json, java.lang.Class<T> classType)Parses the JSON string as the instance ofclassType.static <T> TfromJsonObject(org.json.JSONObject json, java.lang.Class<T> classType)Parses theJSONObjectas the instance ofclassType.static java.lang.StringtoJson(java.lang.Object object)Serialize object to a JSON string.static org.json.JSONObjecttoJsonObject(java.lang.Object object)Serialize object to aJSONObject.
-
-
-
Method Detail
-
fromJson
@Nullable public static <T> T fromJson(@NonNull java.lang.String json, @NonNull java.lang.Class<T> classType)Parses the JSON string as the instance ofclassType.Never throws.
- Type Parameters:
T- target type- Parameters:
json- jsonclassType- class- Returns:
- new instance or
nullin case of errors
-
fromJsonObject
@Nullable public static <T> T fromJsonObject(@NonNull org.json.JSONObject json, @NonNull java.lang.Class<T> classType)Parses theJSONObjectas the instance ofclassType.Never throws.
- Type Parameters:
T- target type- Parameters:
json- jsonclassType- class- Returns:
- new instance or
nullin case of errors
-
toJson
@NonNull public static java.lang.String toJson(@Nullable java.lang.Object object)Serialize object to a JSON string.- Parameters:
object- object- Returns:
- single-line string
-
toJsonObject
@Nullable public static org.json.JSONObject toJsonObject(@Nullable java.lang.Object object)Serialize object to aJSONObject.- Parameters:
object- object- Returns:
- new instance or null
-
-