Package io.gopluslabs.client
Class JSON
- java.lang.Object
-
- io.gopluslabs.client.JSON
-
public class JSON extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJSON.DateTypeAdapterGson TypeAdapter for java.util.Date type If the dateFormat is null, ISO8601Utils will be used.classJSON.LocalDateTypeAdapterGson TypeAdapter for JSR310 LocalDate typestatic classJSON.OffsetDateTimeTypeAdapterGson TypeAdapter for JSR310 OffsetDateTime typestatic classJSON.SqlDateTypeAdapterGson TypeAdapter for java.sql.Date type If the dateFormat is null, a simple "yyyy-MM-dd" format will be used (more efficient than SimpleDateFormat).
-
Field Summary
Fields Modifier and Type Field Description private JSON.DateTypeAdapterdateTypeAdapterprivate com.google.gson.Gsongsonprivate booleanisLenientOnJsonprivate JSON.LocalDateTypeAdapterlocalDateTypeAdapterprivate JSON.OffsetDateTimeTypeAdapteroffsetDateTimeTypeAdapterprivate JSON.SqlDateTypeAdaptersqlDateTypeAdapter
-
Constructor Summary
Constructors Constructor Description JSON()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static com.google.gson.GsonBuildercreateGson()<T> Tdeserialize(String body, Type returnType)Deserialize the given JSON string to Java object.private static <T> Class<? extends T>getClassByDiscriminator(Map<String,Class<? extends T>> classByDiscriminatorValue, String discriminatorValue)private static StringgetDiscriminatorValue(com.google.gson.JsonElement readElement, String discriminatorField)com.google.gson.GsongetGson()Get Gson.Stringserialize(Object obj)Serialize the given Java object into JSON string.JSONsetDateFormat(DateFormat dateFormat)JSONsetGson(com.google.gson.Gson gson)Set Gson.JSONsetLenientOnJson(boolean lenientOnJson)JSONsetLocalDateFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)JSONsetOffsetDateTimeFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)JSONsetSqlDateFormat(DateFormat dateFormat)
-
-
-
Field Detail
-
gson
private com.google.gson.Gson gson
-
isLenientOnJson
private boolean isLenientOnJson
-
dateTypeAdapter
private JSON.DateTypeAdapter dateTypeAdapter
-
sqlDateTypeAdapter
private JSON.SqlDateTypeAdapter sqlDateTypeAdapter
-
offsetDateTimeTypeAdapter
private JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter
-
localDateTypeAdapter
private JSON.LocalDateTypeAdapter localDateTypeAdapter
-
-
Method Detail
-
createGson
public static com.google.gson.GsonBuilder createGson()
-
getDiscriminatorValue
private static String getDiscriminatorValue(com.google.gson.JsonElement readElement, String discriminatorField)
-
getClassByDiscriminator
private static <T> Class<? extends T> getClassByDiscriminator(Map<String,Class<? extends T>> classByDiscriminatorValue, String discriminatorValue)
-
getGson
public com.google.gson.Gson getGson()
Get Gson.- Returns:
- Gson
-
setGson
public JSON setGson(com.google.gson.Gson gson)
Set Gson.- Parameters:
gson- Gson- Returns:
- JSON
-
setLenientOnJson
public JSON setLenientOnJson(boolean lenientOnJson)
-
serialize
public String serialize(Object obj)
Serialize the given Java object into JSON string.- Parameters:
obj- Object- Returns:
- String representation of the JSON
-
deserialize
public <T> T deserialize(String body, Type returnType)
Deserialize the given JSON string to Java object.- Type Parameters:
T- Type- Parameters:
body- The JSON stringreturnType- The type to deserialize into- Returns:
- The deserialized Java object
-
setOffsetDateTimeFormat
public JSON setOffsetDateTimeFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)
-
setLocalDateFormat
public JSON setLocalDateFormat(org.threeten.bp.format.DateTimeFormatter dateFormat)
-
setDateFormat
public JSON setDateFormat(DateFormat dateFormat)
-
setSqlDateFormat
public JSON setSqlDateFormat(DateFormat dateFormat)
-
-