public class JsonHelper extends Object
| Constructor and Description |
|---|
JsonHelper()
Default constructor creates the helper with "prettyPrinting" (carriage returns and indentation) and nulls not
serialized (when serialized you see the null values in the JSON).
|
JsonHelper(boolean prettyPrinting,
boolean serializeNulls)
Create the helper with the given prettyPrinting and serializeNull settings.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
fromJson(com.google.gson.JsonElement json,
Class<T> classOfT)
Converts the given json element into an object of the given class.
|
<T> T |
fromJson(String json,
Class<T> classOfT)
Converts the given json into an object of the given class.
|
<T> T |
fromJson(String json,
Type typeOfT)
Converts the given json into an object of the given type.
|
protected com.google.gson.Gson |
getGson() |
protected void |
registerTypeAdapters(com.google.gson.GsonBuilder builder) |
String |
toJson(Object object)
Converts the given object into a JSON string.
|
public JsonHelper()
public JsonHelper(boolean prettyPrinting,
boolean serializeNulls)
prettyPrinting - true when you want carriages returns and indentation in the JSON outputserializeNulls - true when you want to see null values in the JSON outputpublic <T> T fromJson(com.google.gson.JsonElement json,
Class<T> classOfT)
T - the type of object to be createdjson - the json element to convertclassOfT - the class type to convert the element intopublic <T> T fromJson(String json, Type typeOfT)
T - the type of the object to createjson - the json to parsetypeOfT - the type of object to createpublic <T> T fromJson(String json, Class<T> classOfT)
T - the type of the object to createjson - the json to parseclassOfT - the class type to convert the json intoprotected com.google.gson.Gson getGson()
protected void registerTypeAdapters(com.google.gson.GsonBuilder builder)
Copyright © 2021. All rights reserved.