public interface JsonManager
Json strings and objects.| Modifier and Type | Method and Description |
|---|---|
Object |
clone(Object originalObject)
Tries to clone an object to a
JsonObject or
a JsonArray, if the object is not of
a primitive type (or BigDecimal). |
Object |
clone(Object originalObject,
boolean mutable)
Tries to clone an object to a
JsonObject or
a JsonArray, if the object is not of
a primitive type (or BigDecimal). |
JsonArray |
cloneJsonArray(JsonArray jsonArray,
boolean mutable)
Deep copy of the
JsonArray, so any
modification to the original won't affect the
clone, and vice-versa. |
JsonObject |
cloneJsonObject(JsonObject jsonObject,
boolean mutable)
Deep copy of the
JsonObject, so any
modification to the original won't affect the
clone, and vice-versa. |
String |
convertToJsonDate(Date date)
Converts a Date to a
Json date format. |
Object |
convertToNativeType(Object originalObject)
Convert a random object to a valid native JsonObject type, if
it's not already.
|
JsonObject |
create()
Creates an empty
JsonObject |
JsonArray |
createArray()
Creates an empty
JsonArray. |
JsonObject |
fromClasspathFile(String path)
Creates a
JsonObject from a classpath
Json file. |
JsonObject |
fromFile(File jsonFile)
Creates a
JsonObject from a Json file. |
JsonObject |
fromFile(String jsonFilePath)
Creates a
JsonObject from the path of
a file, on the file system. |
JsonObject |
fromInputStream(InputStream inputStream)
Creates a
JsonObject from an inputStream. |
<T> T |
fromInputStream(InputStream inputStream,
Class<T> clazz)
Creates an instance of the specified
T type
from a Json inputStream. |
JsonArray |
fromInputStreamArray(InputStream inputStream)
Creates a
JsonArray from an inputStream. |
Map<String,Object> |
fromInputStreamToMap(InputStream inputStream)
Creates a
Map<String, Object> from a Json inputStream. |
JsonArray |
fromListArray(List<?> elements)
Creates a
JsonArray from a List
of elements. |
JsonObject |
fromMap(Map<String,?> params)
Creates an empty
JsonObject based on the specified Map. |
JsonObject |
fromMap(Map<String,?> params,
boolean parseKeysAsJsonPaths)
Creates an empty
JsonObject based on the specified Map. |
JsonObject |
fromString(String jsonString)
Creates a
JsonObject from a Json
String. |
<T> T |
fromString(String jsonString,
Class<T> clazz)
Creates an instance of the specified
T type
from a Json String. |
JsonArray |
fromStringArray(String jsonString)
Creates a
JsonArray from a Json
String. |
Map<String,Object> |
fromStringToMap(String jsonString)
Creates a
Map<String, Object> from a Json
String. |
Object |
getElementAtJsonPath(JsonArray array,
String jsonPath)
Gets an element from the
JsonArray at the
specified JsonPath. |
Object |
getElementAtJsonPath(JsonArray array,
String jsonPath,
Object defaultElement)
Gets an element from the
JsonArray at the
specified JsonPath. |
Object |
getElementAtJsonPath(JsonObject obj,
String jsonPath)
Gets an element from the
JsonObject
at the specified JsonPath. |
Object |
getElementAtJsonPath(JsonObject obj,
String jsonPath,
Object defaultElement)
Gets an element from the
JsonObject
at the specified JsonPath. |
boolean |
isElementExists(JsonArray array,
String jsonPath)
Does the array contain an element at
the specified
JsonPath (even if
null)? |
boolean |
isElementExists(JsonObject obj,
String jsonPath)
Does the object contain an element at
the specified
JsonPath (even if
null)? |
Date |
parseDateFromJson(String str)
Converts a
Json date to a Java UTC date. |
void |
putElementAtJsonPath(JsonObjectOrArray obj,
String jsonPath,
Object element)
Puts an element in the object at the specified
JsonPath. |
void |
putElementAtJsonPath(JsonObjectOrArray obj,
String jsonPath,
Object element,
boolean clone)
Puts a clone of the element in the object at the
specified
JsonPath. |
void |
removeElementAtJsonPath(JsonArray array,
String jsonPath)
Removes an element at the specified
JsonPath from the
array. |
void |
removeElementAtJsonPath(JsonObject obj,
String jsonPath)
Removes an element at the specified
JsonPath from the
object. |
String |
toJsonString(Object obj)
Gets the
Json String representation of
the specified object. |
String |
toJsonString(Object obj,
boolean pretty)
Gets the
Json String representation of the
specified object. |
JsonObject create()
JsonObjectJsonObject fromString(String jsonString)
JsonObject from a Json
String.JsonObject fromMap(Map<String,?> params)
JsonObject based 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.
JsonObject fromMap(Map<String,?> params, boolean parseKeysAsJsonPaths)
JsonObject based 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.parseKeysAsJsonPaths - if true, the keys will
be parsed as JsonPaths, otherwise they will ne used
as is.JsonObject fromInputStream(InputStream inputStream)
JsonObject from an inputStream.JsonObject fromFile(File jsonFile)
JsonObject from a Json file.JsonObject fromFile(String jsonFilePath)
JsonObject from the path of
a file, on the file system.JsonObject fromClasspathFile(String path)
JsonObject from a classpath
Json file.the - path to the classpath file. This path always
starts from the root of the classpath.Map<String,Object> fromStringToMap(String jsonString)
Map<String, Object> from a Json
String.Map<String,Object> fromInputStreamToMap(InputStream inputStream)
Map<String, Object> from a Json inputStream.<T> T fromString(String jsonString, Class<T> clazz)
T type
from a Json String.<T> T fromInputStream(InputStream inputStream, Class<T> clazz)
T type
from a Json inputStream.JsonArray createArray()
JsonArray.JsonArray fromStringArray(String jsonString)
JsonArray from a Json
String.JsonArray fromListArray(List<?> elements)
JsonArray from a List
of elements.JsonArray fromInputStreamArray(InputStream inputStream)
JsonArray from an inputStream.String toJsonString(Object obj)
Json String representation of
the specified object.String toJsonString(Object obj, boolean pretty)
Json String representation of the
specified object.pretty - if true, the generated
String will be formatted.Object convertToNativeType(Object originalObject)
Object clone(Object originalObject)
JsonObject or
a JsonArray, if the object is not of
a primitive type (or BigDecimal).
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 JsonArray
if it is a :
Object clone(Object originalObject, boolean mutable)
JsonObject or
a JsonArray, if the object is not of
a primitive type (or BigDecimal).
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 JsonArray
if it is a :
mutable - if false, the resulting
Object and all its potential children
will be immutable.JsonObject cloneJsonObject(JsonObject jsonObject, boolean mutable)
JsonObject, so any
modification to the original won't affect the
clone, and vice-versa.
Note that if the current object is immutable and
the mutable parameter is set to false,
then the current object will be returned as is, since no cloning
is required.
mutable - if true the resulting
array and all its children will be mutable, otherwise
they will all be immutable.JsonArray cloneJsonArray(JsonArray jsonArray, boolean mutable)
JsonArray, so any
modification to the original won't affect the
clone, and vice-versa.
Note that if the current object is immutable and
the mutable parameter is set to false,
then the current array will be returned as is, since no cloning
is required.
mutable - if true the resulting
array and all its children will be mutable, otherwise
they will all be immutable.Object getElementAtJsonPath(JsonObject obj, String jsonPath)
JsonObject
at the specified JsonPath.null if not found.Object getElementAtJsonPath(JsonObject obj, String jsonPath, Object defaultElement)
JsonObject
at the specified JsonPath.null if not found.Object getElementAtJsonPath(JsonArray array, String jsonPath)
JsonArray at the
specified JsonPath.null if not found.Object getElementAtJsonPath(JsonArray array, String jsonPath, Object defaultElement)
JsonArray at the
specified JsonPath.null if not found.void putElementAtJsonPath(JsonObjectOrArray obj, String jsonPath, Object element)
JsonPath.
All the hierarchy to the end of the JsonPath
is created if required.
void putElementAtJsonPath(JsonObjectOrArray obj, String jsonPath, Object element, boolean clone)
JsonPath.
All the hierarchy to the end of the JsonPath
is created if required.
void removeElementAtJsonPath(JsonObject obj, String jsonPath)
JsonPath from the
object.void removeElementAtJsonPath(JsonArray array, String jsonPath)
JsonPath from the
array.boolean isElementExists(JsonObject obj, String jsonPath)
JsonPath (even if
null)?Copyright © 2016. All rights reserved.