public static class JsonUtil.JsonParser
extends java.lang.Object
| Constructor and Description |
|---|
JsonParser() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(java.lang.String source,
java.lang.String key)
Returns
boolean value if the provided key is present
in the supplied JSON source |
java.util.Map<java.lang.String,java.lang.Object> |
get(java.lang.String source,
java.util.Collection<java.lang.String> keys)
Returns a
Map containing JSON paths indicated by keys
as the key and its value, if present, from the JSON source
string. |
java.lang.Object |
get(java.lang.String source,
java.lang.String key)
Returns the value of the JSON attribute indicated by
key from
the JSON source string. |
java.lang.Boolean |
getAsBoolean(java.lang.String source,
java.lang.String key)
Returns
boolean value from the supplied JSON source
associated with the provided key |
java.util.List<java.lang.Object> |
getAsList(java.lang.String source,
java.lang.String key)
Returns
List from the supplied JSON source associated
with the provided key |
java.lang.Number |
getAsNumber(java.lang.String source,
java.lang.String key)
Returns
Number from the supplied JSON source
associated with the provided key |
java.lang.String |
getAsString(java.lang.String source,
java.lang.String key)
Returns the value of the JSON attribute indicated by
key in
the JSON source string as String. |
boolean |
isEmpty(java.lang.String source,
java.lang.String key)
Returns
boolean value for determining the value of
the associated object with the provided key in the supplied JSON
string is empty or not. |
int |
length(java.lang.String source)
Returns the count of element in the supplied JSON string
|
java.lang.Object |
parseJson(java.lang.String source)
Returns Java-equivalent object for the supplied JSON
source. |
java.lang.Object |
parseJson(java.lang.String source,
java.lang.Class<?> targetClass)
Returns object of type
targetClass for the supplied JSON
source. |
java.lang.String |
put(java.lang.String target,
java.lang.String key,
java.lang.Object value)
Associating the specified value with the specified key in the
provided JSON
target.If the the provided target
previously contained a mapping for the key, the oldvalue is replaced. |
java.lang.String |
remove(java.lang.String target,
java.lang.String key)
Removes the mapping for the specified
key from the provided
JSON string target, if present. |
java.lang.String |
toJson(java.lang.Object source)
Converts the JSON
source to JSON string and includes
null values in the returned JSON string if
includeNulls is true. |
java.util.List<java.lang.Object> |
toList(java.lang.String jsonArraySource)
Creates a
List from the supplied JSON
jsonArraySource. |
java.util.Map<java.lang.String,java.lang.Object> |
toMap(java.lang.String source)
Creates a
Map from the supplied JSON source. |
public java.lang.String toJson(java.lang.Object source)
source to JSON string and includes
null values in the returned JSON string if
includeNulls is true.source - Object to convert to JSON formsource objectpublic java.lang.Object parseJson(java.lang.String source)
source.
Below is the JSON source to Java-equivalent mapping:
| JSON Source | Returns |
| Json Array: [...] | List<Object> |
| JSON Map: {...} | Map<String, Object> |
String, Number, Boolean, primitives |
Corresponding Java equivalent class |
source - JSON string for conversionObject post JSON conversionpublic java.lang.Object parseJson(java.lang.String source,
java.lang.Class<?> targetClass)
targetClass for the supplied JSON
source.
If targetClass is null, JsonUtil.JsonParser.parseJson(String) will be
the default invocation.
source - JSON string for conversiontargetClass - name of the class to which the JSON source should be
converted totargetClass, if not null, Java
equivalent Object otherwisepublic java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.String source)
Map from the supplied JSON source.source - JSON string for conversionMap containing JSON key-value pairspublic java.util.List<java.lang.Object> toList(java.lang.String jsonArraySource)
List from the supplied JSON
jsonArraySource.jsonArraySource - JSON string for conversionList contains the array elementspublic java.lang.Object get(java.lang.String source,
java.lang.String key)
key from
the JSON source string.source - JSON source stringkey - key to extract the associated valueObject associated with the key in the
supplied JSON stringpublic java.util.Map<java.lang.String,java.lang.Object> get(java.lang.String source,
java.util.Collection<java.lang.String> keys)
Map containing JSON paths indicated by keys
as the key and its value, if present, from the JSON source
string.source - JSON source stringkeys - keys to extract the associated valueObject associated with the key in the
supplied JSON stringpublic java.lang.String getAsString(java.lang.String source,
java.lang.String key)
key in
the JSON source string as String.source - JSON source stringkey - key to extract the associated value stringkeypublic java.lang.Number getAsNumber(java.lang.String source,
java.lang.String key)
Number from the supplied JSON source
associated with the provided keysource - JSON source stringkey - key to extract the associated NumberNumber with the provided keypublic java.util.List<java.lang.Object> getAsList(java.lang.String source,
java.lang.String key)
List from the supplied JSON source associated
with the provided keysource - JSON source stringkey - key to extract the associated valuekey as
Listpublic java.lang.Boolean getAsBoolean(java.lang.String source,
java.lang.String key)
boolean value from the supplied JSON source
associated with the provided keysource - JSON source stringkey - key to extract the associated valueboolean value with the providedkeypublic boolean containsKey(java.lang.String source,
java.lang.String key)
boolean value if the provided key is present
in the supplied JSON sourcesource - JSON source stringkey - key to identify the presencetrue if the key is present in the supplied JSON
string , else falsepublic boolean isEmpty(java.lang.String source,
java.lang.String key)
boolean value for determining the value of
the associated object with the provided key in the supplied JSON
string is empty or not.source - JSON source stringkey - key to identify associating valuetrue if the value of the associated object
with the key in the supplied JSON string is empty or not
present , else false.public int length(java.lang.String source)
source - JSON source stringpublic java.lang.String remove(java.lang.String target,
java.lang.String key)
key from the provided
JSON string target, if present.target - JSON target stringkey - key to be remove from targeted JSONString of updated target JSON stringpublic java.lang.String put(java.lang.String target,
java.lang.String key,
java.lang.Object value)
target.If the the provided target
previously contained a mapping for the key, the oldvalue is replaced.target - JSON target stringkey - key to be added in target JSON stringvalue - value to be added in targeted JSON targetString with newly added/updated key value pairs