public class JSONObject
extends java.lang.Object
Constructor and Description |
---|
JSONObject() |
JSONObject(boolean createMapper) |
JSONObject(com.fasterxml.jackson.databind.JsonNode json) |
JSONObject(java.lang.Object dataVal) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
convertMapToJsonString(java.util.Map<java.lang.String,java.lang.Object> map)
Converts a Map (String, Object) to a Json String
|
java.util.List<java.lang.Object> |
getArray(java.lang.String key)
Gets a list of Objects by key
|
java.util.List<java.lang.String> |
getArrayString(java.lang.String key)
Gets a list of String by key
|
java.util.List<java.lang.String> |
getArrayString(java.lang.String key,
boolean allowNull)
Gets a list of String by key with/without null values
|
java.lang.Boolean |
getBoolean(java.lang.Object key,
java.lang.Boolean defaultVal)
Gets a Boolean value by key with a default value
|
java.lang.Boolean |
getBoolean(java.lang.String key)
Gets a Boolean value by key
|
int |
getInt(java.lang.Object key,
int defaultVal)
Gets a int value by key with a default value
|
int |
getInt(java.lang.String key)
Gets a int value by key with 0 as default value
|
int |
getJsonArraySize(java.lang.String key)
Gets json size if it is an array
|
long |
getLong(java.lang.Object key,
long defaultVal)
Gets a Long value by key with a default value
|
long |
getLong(java.lang.String key)
Gets a Long value by key
|
java.util.Map<java.lang.String,java.lang.Object> |
getMap(java.lang.String key)
Gets a Map (String, Object) by key
|
com.fasterxml.jackson.databind.ObjectMapper |
getMapper()
Returns the mapper
|
com.fasterxml.jackson.databind.JsonNode |
getNode(java.lang.Object key)
Gets a JsonNode value by key
|
com.fasterxml.jackson.databind.JsonNode |
getNode(java.lang.Object key,
com.fasterxml.jackson.databind.JsonNode defaultVal)
Gets a JsonNode value by key with a default value
|
java.lang.String |
getString(java.lang.Object key)
Gets a String value by key
|
java.lang.String |
getString(java.lang.Object key,
java.lang.String defaultVal)
Gets a String value by key with a default value
|
boolean |
isExist(java.lang.String key)
Checks if the key is existed or not
|
com.fasterxml.jackson.databind.JsonNode |
jsonNode()
Returns the json instance
|
void |
prettyPrint()
Makes pretty print for the json instance
|
void |
put(java.lang.String key,
java.lang.Object val)
Puts (key, value) pairs to the json instance
|
void |
putArray(java.lang.String key,
java.util.List<?> valList)
Puts a list of Objects into Json Array of the json instance
|
void |
putArray(java.lang.String key,
java.lang.Object... vals)
Puts a number of Objects into Json Array of the json instance
|
void |
putMap(java.util.Map<java.lang.String,java.lang.Object> map)
Puts map entries to the json instance
|
static com.fasterxml.jackson.databind.JsonNode |
readInput(java.io.InputStream istream)
Returns a Json node instance from an input stream
|
static com.fasterxml.jackson.databind.JsonNode |
readInput(java.io.Reader reader)
Returns a Json node instance from an input reader
|
static com.fasterxml.jackson.databind.JsonNode |
readInput(java.lang.String jsonString)
Returns a Json node instance from a json String
|
java.lang.String |
toString() |
static java.lang.String |
writeValueAsString(java.lang.Object obj)
Returns a json string from an Object with pretty print
|
static java.lang.String |
writeValueAsString(java.lang.Object obj,
boolean hasPrettyPrint)
Returns a json string from an Object with pretty print as a flag
|
public JSONObject()
public JSONObject(boolean createMapper)
public JSONObject(java.lang.Object dataVal) throws java.io.IOException
java.io.IOException
public JSONObject(com.fasterxml.jackson.databind.JsonNode json)
json
- json node objectpublic static com.fasterxml.jackson.databind.JsonNode readInput(java.lang.String jsonString) throws java.io.IOException
jsonString
- json stringjava.io.IOException
- if I/O error occurspublic static com.fasterxml.jackson.databind.JsonNode readInput(java.io.InputStream istream) throws java.io.IOException
istream
- input stream objectjava.io.IOException
- if I/O error occurspublic static com.fasterxml.jackson.databind.JsonNode readInput(java.io.Reader reader) throws java.io.IOException
reader
- reader objectjava.io.IOException
- if I/O error occurspublic static java.lang.String writeValueAsString(java.lang.Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
obj
- object to be serializedcom.fasterxml.jackson.core.JsonProcessingException
- if problem with processing jsonpublic static java.lang.String writeValueAsString(java.lang.Object obj, boolean hasPrettyPrint) throws com.fasterxml.jackson.core.JsonProcessingException
obj
- object to be serializedhasPrettyPrint
- boolean flag to pretty printcom.fasterxml.jackson.core.JsonProcessingException
- if problem with processing jsonpublic com.fasterxml.jackson.databind.JsonNode jsonNode()
public com.fasterxml.jackson.databind.ObjectMapper getMapper()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isExist(java.lang.String key)
key
- json keypublic int getJsonArraySize(java.lang.String key)
key
- json keypublic com.fasterxml.jackson.databind.JsonNode getNode(java.lang.Object key)
key
- json keypublic com.fasterxml.jackson.databind.JsonNode getNode(java.lang.Object key, com.fasterxml.jackson.databind.JsonNode defaultVal)
key
- a json keydefaultVal
- default json value to return of key not foundpublic java.lang.String getString(java.lang.Object key)
key
- a json keypublic java.lang.String getString(java.lang.Object key, java.lang.String defaultVal)
key
- a json keydefaultVal
- default string value to return of key not foundpublic int getInt(java.lang.String key)
key
- a json keypublic int getInt(java.lang.Object key, int defaultVal)
key
- a json keydefaultVal
- default integer value to return of key not foundpublic java.lang.Boolean getBoolean(java.lang.String key)
key
- a json keypublic java.lang.Boolean getBoolean(java.lang.Object key, java.lang.Boolean defaultVal)
key
- a json keydefaultVal
- default boolean value to return of key not foundpublic long getLong(java.lang.String key)
key
- a json keypublic long getLong(java.lang.Object key, long defaultVal)
key
- a json keydefaultVal
- default long value to return of key not foundpublic java.util.List<java.lang.Object> getArray(java.lang.String key)
key
- a json keypublic java.util.Map<java.lang.String,java.lang.Object> getMap(java.lang.String key)
key
- a json keypublic java.lang.String convertMapToJsonString(java.util.Map<java.lang.String,java.lang.Object> map) throws com.fasterxml.jackson.core.JsonProcessingException
map
- a map of (String, Object)com.fasterxml.jackson.core.JsonProcessingException
- if problem with processing jsonpublic void putMap(java.util.Map<java.lang.String,java.lang.Object> map)
map
- a map of (String, Object)public java.util.List<java.lang.String> getArrayString(java.lang.String key, boolean allowNull)
key
- a json keyallowNull
- boolean flag to allow for null valuespublic java.util.List<java.lang.String> getArrayString(java.lang.String key)
key
- a json keypublic void put(java.lang.String key, java.lang.Object val)
key
- a json keyval
- a json valuepublic void putArray(java.lang.String key, java.lang.Object... vals)
key
- a json keyvals
- a varargs for object/spublic void putArray(java.lang.String key, java.util.List<?> valList)
key
- a json keyvalList
- a list object of valuespublic void prettyPrint()