Interface JsonManager
- All Known Implementing Classes:
SpincastGsonManager,SpincastJsonManager
Json strings and objects.-
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.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.enumsToFriendlyJsonArray(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.getElementAtJsonPath(JsonArray array, String jsonPath) Gets an element from theJsonArrayat the specifiedJsonPath.getElementAtJsonPath(JsonArray array, String jsonPath, Object defaultElement) 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 defaultElement) Gets an element from theJsonObjectat the specifiedJsonPath.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 obj, String jsonPath, Object element) Puts an element in the object at the specifiedJsonPath.voidputElementAtJsonPath(JsonObjectOrArray obj, String jsonPath, Object element, boolean clone) Puts a clone of the element in the object at the specifiedJsonPath.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.
-
Method Details
-
create
JsonObject create()Creates an emptyJsonObject -
createArray
JsonArray createArray()Creates an emptyJsonArray. -
fromObject
Creates aJsonObjectfrom a random object.. -
fromString
Creates aJsonObjectfrom aJsonString.- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromMap
Creates 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.
- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromMap
Creates 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.- Parameters:
parseKeysAsJsonPaths- 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
Creates aJsonObjectfrom an inputStream.- Returns:
- the
JsonObjectversion of the parameter ornullif the parameter isnull.
-
fromFile
Creates aJsonObjectfrom a Json file.- Returns:
- the deserialized
JsonObjectornullif the file isnullor doesn't exist.
-
fromFile
Creates aJsonObjectfrom the path of a file, on the file system.- Returns:
- the deserialized
JsonObjectornullif the file isnullor doesn't exist.
-
fromClasspathFile
Creates aJsonObjectfrom a classpath Json file.- Parameters:
the- path to the classpath file. This path always starts from the root of the classpath.- Returns:
- the deserialized
JsonObjectornullif the file doesn't exist. - Throws:
Exception- if the path isnull
-
fromStringToMap
Creates aMap<String, Object>from aJsonString.- Returns:
- the
Mapversion of the parameter ornullif the parameter isnull.
-
fromInputStreamToMap
Creates aMap<String, Object>from aJsoninputStream.- Returns:
- the
Mapversion of the parameter ornullif the parameter isnull.
-
fromString
Creates an instance of the specifiedTtype from aJsonString.- Returns:
- the deserialized version of the
parameter or
nullif the parameter isnull.
-
fromInputStream
Creates an instance of the specifiedTtype from aJsoninputStream.- Returns:
- the deserialized version of the
parameter or
nullif the parameter isnull.
-
fromCollectionToJsonArray
Creates aJsonArrayfrom a random collection. -
fromStringArray
Creates aJsonArrayfrom aJsonString.- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
fromListArray
Creates aJsonArrayfrom aListof elements.- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
fromInputStreamArray
Creates aJsonArrayfrom an inputStream.- Returns:
- the
JsonArrayversion of the parameter ornullif the parameter isnull.
-
createForm
Creates an emptyForm, which is a JsonObject + a validations container. -
toJsonString
Gets theJsonString representation of the specified object. -
toJsonString
Gets theJsonString representation of the specified object.- Parameters:
pretty- iftrue, the generated String will be formatted.
-
parseDateFromJson
Converts aJsondate (ISO-8601) to a JavaUTCdate. -
convertToJsonDate
Converts a Date to aJsondate format. -
convertToNativeType
Convert a random object to a valid native JsonObject type, if it's not already. -
clone
Tries 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
-
clone
Tries 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
- Parameters:
mutable- iffalse, the resulting Object and all its potential children will be immutable.
-
cloneJsonObject
Deep 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.- Parameters:
mutable- iftruethe resulting array and all its children will be mutable, otherwise they will all be immutable.
-
cloneJsonArray
Deep 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.- Parameters:
mutable- iftruethe resulting array and all its children will be mutable, otherwise they will all be immutable.
-
getElementAtJsonPath
Gets an element from theJsonObjectat the specifiedJsonPath.- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Gets an element from theJsonObjectat the specifiedJsonPath.- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Gets an element from theJsonArrayat the specifiedJsonPath.- Returns:
- the element or
nullif not found.
-
getElementAtJsonPath
Gets an element from theJsonArrayat the specifiedJsonPath.- Returns:
- the element or
nullif not found.
-
putElementAtJsonPath
Puts an element in the object at the specifiedJsonPath.All the hierarchy to the end of the
JsonPathis created if required. -
putElementAtJsonPath
Puts a clone of the element in the object at the specifiedJsonPath.All the hierarchy to the end of the
JsonPathis created if required. -
removeElementAtJsonPath
Removes an element at the specifiedJsonPathfrom the object. -
removeElementAtJsonPath
Removes an element at the specifiedJsonPathfrom the array. -
isElementExists
Does the object contain an element at the specifiedJsonPath(even ifnull)? -
isElementExists
Does the array contain an element at the specifiedJsonPath(even ifnull)? -
enumToFriendlyJsonObject
Convert the enum value to aJsonObjectthat has a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum) -
enumsToFriendlyJsonArray
Convert the enums to an array ofJsonObjectsthat have a ".name" property (thename()of the enum) and a ".label" property (thetoString()of the enum).
-