Class SpincastJsonManager
- All Implemented Interfaces:
JsonManager
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSpincastJsonManager(com.google.inject.Provider<com.google.inject.Injector> guiceProvider, JsonObjectFactory jsonObjectFactory, Set<JsonMixinInfo> jsonMixinInfos, SpincastJsonManagerConfig spincastJsonManagerConfig, SpincastConfig spincastConfig, JsonPathUtils jsonPathUtils, SpincastUtils spincastUtils, FormFactory formFactory) -
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 voidconfigureEmptyBeans(com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected voidconfigureMixins(com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected voidconfigureObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Configuration of the ObjectMapper.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 com.fasterxml.jackson.databind.ObjectMapperCreates the ObjectMapperenumsToFriendlyJsonArray(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.fasterxml.jackson.databind.JsonSerializer<BigDecimal>protected com.fasterxml.jackson.databind.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.fasterxml.jackson.databind.JsonSerializer<Enum<?>>protected FormFactoryprotected com.google.inject.InjectorgetGuice()protected com.fasterxml.jackson.databind.JsonSerializer<Instant>protected com.fasterxml.jackson.core.util.DefaultPrettyPrinterprotected Stringprotected Stringprotected com.fasterxml.jackson.databind.JsonDeserializer<JsonArray>protected com.fasterxml.jackson.databind.JsonSerializer<JsonArray>protected Set<JsonMixinInfo>protected com.fasterxml.jackson.databind.JsonDeserializer<JsonObject>protected JsonObjectFactoryprotected com.fasterxml.jackson.databind.JsonSerializer<JsonObject>protected JsonPathUtilsprotected intprotected com.fasterxml.jackson.databind.ObjectMapperprotected SpincastConfigprotected SpincastJsonManagerConfigprotected SpincastUtilsprotected voidinjectDependencies(Object obj) Once the deserialization of an Object is done, we inject dependencies using Guice.protected booleanShould comments be accepted in Json?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) Currently support ISO 8601 encoded dates.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 voidregisterCustomModules(com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected voidregisterCustomTypeSerializerModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register our custom serializers for some types.protected voidregisterJava8DatatypesModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected voidregisterJsonObjectModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register our custom (de)serializers for JsonObjectvoidremoveElementAtJsonPath(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.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
ENUM_SERIALIZER_FIELD_NAME_NAME
- See Also:
-
ENUM_SERIALIZER_FIELD_NAME_LABEL
- See Also:
-
-
Constructor Details
-
SpincastJsonManager
@Inject public SpincastJsonManager(com.google.inject.Provider<com.google.inject.Injector> guiceProvider, JsonObjectFactory jsonObjectFactory, @Nullable Set<JsonMixinInfo> jsonMixinInfos, SpincastJsonManagerConfig spincastJsonManagerConfig, SpincastConfig spincastConfig, JsonPathUtils jsonPathUtils, SpincastUtils spincastUtils, FormFactory formFactory)
-
-
Method Details
-
getGuice
protected com.google.inject.Injector getGuice() -
getJsonObjectFactory
-
getJsonMixinInfos
-
getSpincastJsonManagerConfig
-
getSpincastConfig
-
getJsonPathUtils
-
getSpincastUtils
-
getFormFactory
-
getJacksonPrettyPrinter
protected com.fasterxml.jackson.core.util.DefaultPrettyPrinter getJacksonPrettyPrinter() -
getJacksonPrettyPrinterNewline
-
getJacksonPrettyPrinterIndentation
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
createObjectManager
protected com.fasterxml.jackson.databind.ObjectMapper createObjectManager()Creates the ObjectMapper -
configureObjectMapper
protected void configureObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Configuration of the ObjectMapper. -
isAllowCommentsInJson
protected boolean isAllowCommentsInJson()Should comments be accepted in Json? -
configureEmptyBeans
protected void configureEmptyBeans(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
configureMixins
protected void configureMixins(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
getJsonObjectSerializer
-
getEnumSerializer
-
getJsonArraySerializer
-
getDateSerializer
-
getInstantSerializer
-
getBigDecimalSerializer
-
getJsonObjectDeserializer
-
getJsonArrayDeserializer
-
registerCustomModules
protected void registerCustomModules(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
registerJsonObjectModule
protected void registerJsonObjectModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register our custom (de)serializers for JsonObject -
registerCustomTypeSerializerModule
protected void registerCustomTypeSerializerModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) Register our custom serializers for some types. -
registerJava8DatatypesModule
protected void registerJava8DatatypesModule(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
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.
-
injectDependencies
Once the deserialization of an Object is done, we inject dependencies using Guice. -
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
-
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.
-
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.
-
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.
-
fromFile
Description copied from interface:JsonManagerCreates aJsonObjectfrom a Json file.- Specified by:
fromFilein interfaceJsonManager- Returns:
- the deserialized
JsonObjectornullif the file isnullor doesn't exist.
-
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.
-
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.
-
getMaxNumberOfKeysWhenConvertingMapToJsonObject
protected int getMaxNumberOfKeysWhenConvertingMapToJsonObject() -
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
-
createForm
Description copied from interface:JsonManagerCreates an emptyForm, which is a JsonObject + a validations container.- Specified by:
createFormin interfaceJsonManager
-
convertToJsonDate
Description copied from interface:JsonManagerConverts a Date to aJsondate format.- Specified by:
convertToJsonDatein interfaceJsonManager
-
parseDateFromJson
Currently support ISO 8601 encoded dates.- Specified by:
parseDateFromJsonin 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
-
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.
-
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.
-
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
-