Class SpincastGsonManager
- All Implemented Interfaces:
JsonManager
-
Constructor Summary
ConstructorsConstructorDescriptionSpincastGsonManager(com.google.gson.JsonDeserializer<JsonObject> jsonObjectDeserializer, com.google.gson.JsonDeserializer<JsonArray> jsonArrayDeserializer, com.google.gson.JsonSerializer<JsonObject> jsonObjectSerializer, com.google.gson.JsonSerializer<JsonArray> jsonArraySerializer, com.google.gson.JsonSerializer<Date> dateSerializer, com.google.gson.JsonSerializer<Instant> instantSerializer, com.google.gson.JsonSerializer<BigDecimal> bigDecimalSerializer, com.google.gson.JsonSerializer<Enum<?>> enumSerializer, com.google.gson.JsonSerializer<Class<?>> classSerializer, com.google.gson.JsonSerializer<Throwable> throwableSerializer, JsonPathUtils jsonPathUtils, JsonObjectFactory jsonObjectFactory, SpincastConfig spincastConfig, SpincastUtils spincastUtils, FormFactory formFactory, com.google.inject.Provider<com.google.inject.Injector> guiceProvider) -
Method Summary
Modifier and TypeMethodDescriptionTries to clone an object to aJsonObjector aJsonArray, if the object is not of a primitive type (orBigDecimal).Tries to clone an object to aJsonObjector aJsonArray, if the object is not of a primitive type (orBigDecimal).cloneJsonArray(JsonArray jsonArray, boolean mutable) Deep copy of theJsonArray, so any modification to the original won't affect the clone, and vice-versa.cloneJsonObject(JsonObject jsonObject, boolean mutable) Deep copy of theJsonObject, so any modification to the original won't affect the clone, and vice-versa.protected voidconfigureGsonBuilder(com.google.gson.GsonBuilder gsonBuilder) Configure the Gson buildercom.google.gson.JsonElementconvertJsonObjectElementToGsonJsonElement(Object originalObject) convertToJsonDate(Date date) Converts a Date to aJsondate format.convertToNativeType(Object originalObject) Convert a random object to a valid native JsonObject type, if it's not already.create()Creates an emptyJsonObjectCreates an emptyJsonArray.createForm(String formName) Creates an emptyForm, which is a JsonObject + a validations container.protected voidenumsToFriendlyJsonArray(Enum<?>[] enumValues) Convert the enums to an array ofJsonObjectsthat have a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum).enumToFriendlyJsonObject(Enum<?> enumValue) Convert the enum value to aJsonObjectthat has a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum)fromClasspathFile(String path) Creates aJsonObjectfrom a classpath Json file.fromCollectionToJsonArray(Collection<?> collection) Creates aJsonArrayfrom a random collection.Creates aJsonObjectfrom a Json file.Creates aJsonObjectfrom the path of a file, on the file system.fromInputStream(InputStream inputStream) Creates aJsonObjectfrom an inputStream.<T> TfromInputStream(InputStream inputStream, Class<T> clazz) Creates an instance of the specifiedTtype from aJsoninputStream.fromInputStreamArray(InputStream inputStream) Creates aJsonArrayfrom an inputStream.fromInputStreamToMap(InputStream inputStream) Creates aMap<String, Object>from aJsoninputStream.fromListArray(List<?> elements) Creates aJsonArrayfrom aListof elements.Creates an emptyJsonObjectbased on the specified Map.Creates aJsonObjectbased on the specified Map.fromObject(Object object) Creates aJsonObjectfrom a random object..fromString(String jsonString) Creates aJsonObjectfrom aJsonString.<T> TfromString(String jsonString, Class<T> clazz) Creates an instance of the specifiedTtype from aJsonString.fromStringArray(String jsonString) Creates aJsonArrayfrom aJsonString.fromStringToMap(String jsonString) Creates aMap<String, Object>from aJsonString.protected com.google.gson.JsonSerializer<BigDecimal>protected com.google.gson.JsonSerializer<Class<?>>protected com.google.gson.JsonSerializer<Date>getElementAtJsonPath(JsonArray array, String jsonPath) Gets an element from theJsonArrayat the specifiedJsonPath.getElementAtJsonPath(JsonArray array, String jsonPath, Object defaultValue) Gets an element from theJsonArrayat the specifiedJsonPath.getElementAtJsonPath(JsonObject obj, String jsonPath) Gets an element from theJsonObjectat the specifiedJsonPath.getElementAtJsonPath(JsonObject obj, String jsonPath, Object defaultValue) Gets an element from theJsonObjectat the specifiedJsonPath.protected com.google.gson.JsonSerializer<Enum<?>>protected FormFactoryprotected Stringprotected Stringprotected Stringcom.google.gson.GsongetGson()com.google.gson.Gsonprotected com.google.inject.InjectorgetGuice()protected com.google.gson.JsonSerializer<Instant>protected com.google.gson.JsonDeserializer<JsonArray>protected com.google.gson.JsonSerializer<JsonArray>protected com.google.gson.JsonDeserializer<JsonObject>protected JsonObjectFactoryprotected com.google.gson.JsonSerializer<JsonObject>protected JsonPathUtilsprotected intprotected ObjectgetObjectFromGsonJsonElement(com.google.gson.JsonElement jsonElement) protected SpincastConfigprotected SpincastUtilsprotected com.google.gson.JsonSerializer<Throwable>protected voidinjectDependencies(Object obj) Once the deserialization of an Object is done, we inject dependencies using Guice.booleanisElementExists(JsonArray array, String jsonPath) Does the array contain an element at the specifiedJsonPath(even ifnull)?booleanisElementExists(JsonObject obj, String jsonPath) Does the object contain an element at the specifiedJsonPath(even ifnull)?parseDateFromJson(String str) Converts aJsondate (ISO-8601) to a JavaUTCdate.voidputElementAtJsonPath(JsonObjectOrArray objOrArray, String jsonPath, Object value) Puts an element in the object at the specifiedJsonPath.voidputElementAtJsonPath(JsonObjectOrArray objOrArray, String jsonPath, Object value, boolean clone) Puts a clone of the element in the object at the specifiedJsonPath.protected voidregisterBigDecimalSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterClassSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterCustomDeserializers(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterCustomSerializers(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterDateSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterEnumSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterInstantSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterJsonArrayDeserializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterJsonArraySerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterJsonObjectDeserializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterJsonObjectSerializer(com.google.gson.GsonBuilder gsonBuilder) protected voidregisterThrowableSerializer(com.google.gson.GsonBuilder gsonBuilder) voidremoveElementAtJsonPath(JsonArray array, String jsonPath) Removes an element at the specifiedJsonPathfrom the array.voidremoveElementAtJsonPath(JsonObject obj, String jsonPath) Removes an element at the specifiedJsonPathfrom the object.toJsonString(Object obj) Gets theJsonString representation of the specified object.toJsonString(Object obj, boolean pretty) Gets theJsonString representation of the specified object.
-
Constructor Details
-
SpincastGsonManager
@Inject public SpincastGsonManager(com.google.gson.JsonDeserializer<JsonObject> jsonObjectDeserializer, com.google.gson.JsonDeserializer<JsonArray> jsonArrayDeserializer, com.google.gson.JsonSerializer<JsonObject> jsonObjectSerializer, com.google.gson.JsonSerializer<JsonArray> jsonArraySerializer, com.google.gson.JsonSerializer<Date> dateSerializer, com.google.gson.JsonSerializer<Instant> instantSerializer, com.google.gson.JsonSerializer<BigDecimal> bigDecimalSerializer, com.google.gson.JsonSerializer<Enum<?>> enumSerializer, com.google.gson.JsonSerializer<Class<?>> classSerializer, com.google.gson.JsonSerializer<Throwable> throwableSerializer, JsonPathUtils jsonPathUtils, JsonObjectFactory jsonObjectFactory, SpincastConfig spincastConfig, SpincastUtils spincastUtils, FormFactory formFactory, com.google.inject.Provider<com.google.inject.Injector> guiceProvider)
-
-
Method Details
-
getJsonObjectDeserializer
-
getJsonArrayDeserializer
-
getJsonObjectSerializer
-
getJsonArraySerializer
-
getDateSerializer
-
getInstantSerializer
-
getBigDecimalSerializer
-
getEnumSerializer
-
getClassSerializer
-
getThrowableSerializer
-
getJsonPathUtils
-
getJsonObjectFactory
-
getSpincastConfig
-
getSpincastUtils
-
getFormFactory
-
getGuice
protected com.google.inject.Injector getGuice() -
getGson
public com.google.gson.Gson getGson() -
getGsonPrettyPrinting
public com.google.gson.Gson getGsonPrettyPrinting() -
createGsons
protected void createGsons() -
configureGsonBuilder
protected void configureGsonBuilder(com.google.gson.GsonBuilder gsonBuilder) Configure the Gson builder -
registerCustomDeserializers
protected void registerCustomDeserializers(com.google.gson.GsonBuilder gsonBuilder) -
registerJsonObjectDeserializer
protected void registerJsonObjectDeserializer(com.google.gson.GsonBuilder gsonBuilder) -
registerJsonArrayDeserializer
protected void registerJsonArrayDeserializer(com.google.gson.GsonBuilder gsonBuilder) -
registerCustomSerializers
protected void registerCustomSerializers(com.google.gson.GsonBuilder gsonBuilder) -
registerJsonObjectSerializer
protected void registerJsonObjectSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerJsonArraySerializer
protected void registerJsonArraySerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerDateSerializer
protected void registerDateSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerInstantSerializer
protected void registerInstantSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerBigDecimalSerializer
protected void registerBigDecimalSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerEnumSerializer
protected void registerEnumSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerClassSerializer
protected void registerClassSerializer(com.google.gson.GsonBuilder gsonBuilder) -
registerThrowableSerializer
protected void registerThrowableSerializer(com.google.gson.GsonBuilder gsonBuilder) -
create
Description copied from interface:JsonManagerCreates an emptyJsonObject- Specified by:
createin interfaceJsonManager
-
createArray
Description copied from interface:JsonManagerCreates an emptyJsonArray.- Specified by:
createArrayin interfaceJsonManager
-
fromObject
Description copied from interface:JsonManagerCreates aJsonObjectfrom a random object..- Specified by:
fromObjectin interfaceJsonManager
-
fromMap
Description copied from interface:JsonManagerCreates an emptyJsonObjectbased on the specified Map. An attempt will be made to create a deep copy of every elements so a modification won't affect any external references and vice-versa.The keys will be used as is, not parsed as JsonPaths.
- Specified by:
fromMapin interfaceJsonManager- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromMap
Description copied from interface:JsonManagerCreates aJsonObjectbased on the specified Map. An attempt will be made to create a deep copy of every elements so a modification won't affect any external references and vice-versa.- Specified by:
fromMapin interfaceJsonManagerparseKeysAsJsonPaths- iftrue, the keys will be parsed asJsonPaths, otherwise they will ne used as is.- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromInputStream
Description copied from interface:JsonManagerCreates aJsonObjectfrom an inputStream.- Specified by:
fromInputStreamin interfaceJsonManager- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
getFromInputStreamEncoding
-
fromFile
Description copied from interface:JsonManagerCreates aJsonObjectfrom a Json file.- Specified by:
fromFilein interfaceJsonManager- Returns:
- the deserialized
JsonObjectornullif the file isnullor doesn't exist.
-
getFromFileEncoding
-
fromFile
Description copied from interface:JsonManagerCreates aJsonObjectfrom the path of a file, on the file system.- Specified by:
fromFilein interfaceJsonManager- Returns:
- the deserialized
JsonObjectornullif the file isnullor doesn't exist.
-
fromClasspathFile
Description copied from interface:JsonManagerCreates aJsonObjectfrom a classpath Json file.- Specified by:
fromClasspathFilein interfaceJsonManager- Returns:
- the deserialized
JsonObjectornullif the file doesn't exist.
-
getFromClasspathFileEncoding
-
fromStringToMap
Description copied from interface:JsonManagerCreates aMap<String, Object>from aJsonString.- Specified by:
fromStringToMapin interfaceJsonManager- Returns:
- the
Mapversion of the parameter ornullif the parameter isnull.
-
fromInputStreamToMap
Description copied from interface:JsonManagerCreates aMap<String, Object>from aJsoninputStream.- Specified by:
fromInputStreamToMapin interfaceJsonManager- Returns:
- the
Mapversion of the parameter ornullif the parameter isnull.
-
fromString
Description copied from interface:JsonManagerCreates aJsonObjectfrom aJsonString.- Specified by:
fromStringin interfaceJsonManager- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromString
Description copied from interface:JsonManagerCreates an instance of the specifiedTtype from aJsonString.- Specified by:
fromStringin interfaceJsonManager- Returns:
- the deserialized version of the
parameter or
nullif the parameter isnull.
-
fromInputStream
Description copied from interface:JsonManagerCreates an instance of the specifiedTtype from aJsoninputStream.- Specified by:
fromInputStreamin interfaceJsonManager- Returns:
- the deserialized version of the
parameter or
nullif the parameter isnull.
-
fromCollectionToJsonArray
Description copied from interface:JsonManagerCreates aJsonArrayfrom a random collection.- Specified by:
fromCollectionToJsonArrayin interfaceJsonManager
-
fromStringArray
Description copied from interface:JsonManagerCreates aJsonArrayfrom aJsonString.- Specified by:
fromStringArrayin interfaceJsonManager- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
fromListArray
Description copied from interface:JsonManagerCreates aJsonArrayfrom aListof elements.- Specified by:
fromListArrayin interfaceJsonManager- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
fromInputStreamArray
Description copied from interface:JsonManagerCreates aJsonArrayfrom an inputStream.- Specified by:
fromInputStreamArrayin interfaceJsonManager- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
createForm
Description copied from interface:JsonManagerCreates an emptyForm, which is a JsonObject + a validations container.- Specified by:
createFormin interfaceJsonManager
-
toJsonString
Description copied from interface:JsonManagerGets theJsonString representation of the specified object.- Specified by:
toJsonStringin interfaceJsonManager
-
toJsonString
Description copied from interface:JsonManagerGets theJsonString representation of the specified object.- Specified by:
toJsonStringin interfaceJsonManagerpretty- iftrue, the generated String will be formatted.
-
parseDateFromJson
Description copied from interface:JsonManagerConverts aJsondate (ISO-8601) to a JavaUTCdate.- Specified by:
parseDateFromJsonin interfaceJsonManager
-
convertToJsonDate
Description copied from interface:JsonManagerConverts a Date to aJsondate format.- Specified by:
convertToJsonDatein interfaceJsonManager
-
convertToNativeType
Description copied from interface:JsonManagerConvert a random object to a valid native JsonObject type, if it's not already.- Specified by:
convertToNativeTypein interfaceJsonManager
-
convertJsonObjectElementToGsonJsonElement
-
getObjectFromGsonJsonElement
-
clone
Description copied from interface:JsonManagerTries to clone an object to aJsonObjector aJsonArray, if the object is not of a primitive type (orBigDecimal).The cloning is made by serializing the Object to a Json string, and deserializing back. So any (de)serialization rules apply.
The non primitive object will be cloned to a
JsonArrayif it is a :- JsonArray
- Collection
- Array
- Specified by:
clonein interfaceJsonManager
-
clone
Description copied from interface:JsonManagerTries to clone an object to aJsonObjector aJsonArray, if the object is not of a primitive type (orBigDecimal).The cloning is made by serializing the Object to a Json string, and deserializing back. So any (de)serialization rules apply.
The non primitive object will be cloned to a
JsonArrayif it is a :- JsonArray
- Collection
- Array
- Specified by:
clonein interfaceJsonManagermutable- iffalse, the resulting Object and all its potential children will be immutable.
-
cloneJsonObject
Description copied from interface:JsonManagerDeep copy of theJsonObject, so any modification to the original won't affect the clone, and vice-versa.Note that if the current object is immutable and the
mutableparameter is set tofalse, then the current object will be returned as is, since no cloning is required.- Specified by:
cloneJsonObjectin interfaceJsonManagermutable- iftruethe resulting array and all its children will be mutable, otherwise they will all be immutable.
-
cloneJsonArray
Description copied from interface:JsonManagerDeep copy of theJsonArray, so any modification to the original won't affect the clone, and vice-versa.Note that if the current object is immutable and the
mutableparameter is set tofalse, then the current array will be returned as is, since no cloning is required.- Specified by:
cloneJsonArrayin interfaceJsonManagermutable- iftruethe resulting array and all its children will be mutable, otherwise they will all be immutable.
-
removeElementAtJsonPath
Description copied from interface:JsonManagerRemoves an element at the specifiedJsonPathfrom the object.- Specified by:
removeElementAtJsonPathin interfaceJsonManager
-
removeElementAtJsonPath
Description copied from interface:JsonManagerRemoves an element at the specifiedJsonPathfrom the array.- Specified by:
removeElementAtJsonPathin interfaceJsonManager
-
isElementExists
Description copied from interface:JsonManagerDoes the object contain an element at the specifiedJsonPath(even ifnull)?- Specified by:
isElementExistsin interfaceJsonManager
-
isElementExists
Description copied from interface:JsonManagerDoes the array contain an element at the specifiedJsonPath(even ifnull)?- Specified by:
isElementExistsin interfaceJsonManager
-
enumToFriendlyJsonObject
Description copied from interface:JsonManagerConvert the enum value to aJsonObjectthat has a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum)- Specified by:
enumToFriendlyJsonObjectin interfaceJsonManager
-
enumsToFriendlyJsonArray
Description copied from interface:JsonManagerConvert the enums to an array ofJsonObjectsthat have a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum).- Specified by:
enumsToFriendlyJsonArrayin interfaceJsonManager
-
getElementAtJsonPath
Description copied from interface:JsonManagerGets an element from theJsonObjectat the specifiedJsonPath.- Specified by:
getElementAtJsonPathin interfaceJsonManager- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Description copied from interface:JsonManagerGets an element from theJsonObjectat the specifiedJsonPath.- Specified by:
getElementAtJsonPathin interfaceJsonManager- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Description copied from interface:JsonManagerGets an element from theJsonArrayat the specifiedJsonPath.- Specified by:
getElementAtJsonPathin interfaceJsonManager- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Description copied from interface:JsonManagerGets an element from theJsonArrayat the specifiedJsonPath.- Specified by:
getElementAtJsonPathin interfaceJsonManager- Returns:
- the element or
nullif not found.
-
putElementAtJsonPath
Description copied from interface:JsonManagerPuts an element in the object at the specifiedJsonPath.All the hierarchy to the end of the
JsonPathis created if required.- Specified by:
putElementAtJsonPathin interfaceJsonManager
-
putElementAtJsonPath
public void putElementAtJsonPath(JsonObjectOrArray objOrArray, String jsonPath, Object value, boolean clone) Description copied from interface:JsonManagerPuts a clone of the element in the object at the specifiedJsonPath.All the hierarchy to the end of the
JsonPathis created if required.- Specified by:
putElementAtJsonPathin interfaceJsonManager
-
getMaxNumberOfKeysWhenConvertingMapToJsonObject
protected int getMaxNumberOfKeysWhenConvertingMapToJsonObject() -
injectDependencies
Once the deserialization of an Object is done, we inject dependencies using Guice.
-