public class JsonUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static JsonUtil |
JU
The singleton of this class (i.e.
|
Modifier | Constructor and Description |
---|---|
protected |
JsonUtil() |
Modifier and Type | Method and Description |
---|---|
void |
appendJSONArray(java.lang.Appendable output,
java.lang.Object... objects)
Appends the given object array to the given output in a valid JSON
string representation.
|
void |
appendJSONConvertible(java.lang.Appendable output,
IJSONConvertible jsonConvertible)
Converts the given object to a valid JSON string representation and appends
it to the given buffer.
|
void |
appendJSONMap(java.lang.Appendable output,
java.util.Map<java.lang.String,java.lang.Object> map)
Adds the given map to the buffer as JSON representation.
|
void |
appendJSONObject(java.lang.Appendable output,
java.lang.Object object)
Appends the given object to the output as a valid JSON string.
|
void |
appendJsonPair(java.lang.Appendable output,
java.lang.String name,
java.lang.Object value)
Appends the given name and value as JSON pair member to the given buffer.
|
void |
appendJSONPair(java.lang.Appendable output,
java.lang.String name,
java.lang.Object value)
Appends the given name and value as JSON pair member to the given buffer.
|
void |
appendJsonPair(java.lang.Appendable output,
java.lang.String name,
java.lang.Object value,
boolean compact)
Appends the given name and value as JSON pair member to the given output.
|
void |
appendJSONString(java.lang.Appendable output,
java.lang.String str)
Appends the given string to the buffer as a valid JSON string literal.
|
java.lang.String |
arrayToJSON(java.lang.Object... objects)
Converts the given object array to a valid JSON string representation.
|
java.lang.String |
convertToJSON(IJSONConvertible jsonConvertible)
Converts the given object to a valid JSON string representation.
|
static JsonUtil |
current()
Returns the only instance this class supports (design pattern "Singleton")
|
boolean |
isValidJsonType(java.lang.Class<?> type)
Returns true if the given class one of the supported JSON object types.
|
boolean |
isValidJsonTypeInstance(java.lang.Object object)
Returns true if the given object is null or an instance of one of the
supported JSON object types.
|
java.lang.String |
mapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
Converts the given map to a valid JSON string representation.
|
java.lang.String |
objectToJSONValue(java.lang.Object object)
Tries to convert the given object to a JSON string.
|
java.lang.String |
toJSONStringLiteral(java.lang.String str)
Returns the given string as JSON string literal (i.e.
|
public static final JsonUtil JU
public static JsonUtil current()
public java.lang.String convertToJSON(IJSONConvertible jsonConvertible)
jsonConvertible
- The object to convert.public java.lang.String arrayToJSON(java.lang.Object... objects)
objects
- The object array to convert.public java.lang.String mapToJSON(java.util.Map<java.lang.String,java.lang.Object> map)
map
- The map to convert.public java.lang.String toJSONStringLiteral(java.lang.String str)
str
- The string to make JSON compatible (might by null)public void appendJSONPair(java.lang.Appendable output, java.lang.String name, java.lang.Object value)
output
- The buffer to append to.name
- The name of the pair.value
- The value of the pair.IORuntimeException
- if the given output object throws an IOException.public void appendJsonPair(java.lang.Appendable output, java.lang.String name, java.lang.Object value)
output
- The buffer to append to.name
- The name of the pair.value
- The value of the pair.IORuntimeException
- if the given output object throws an IOException.public void appendJsonPair(java.lang.Appendable output, java.lang.String name, java.lang.Object value, boolean compact)
output
- The buffer to append to.name
- The name of the pair.value
- The value of the pair.compact
- if true, no spaces are inserted between name and separator and separator and value.IORuntimeException
- if the given output object throws an IOException.public void appendJSONString(java.lang.Appendable output, java.lang.String str)
IORuntimeException
- if the given output object throws an IOException.public void appendJSONConvertible(java.lang.Appendable output, IJSONConvertible jsonConvertible)
jsonConvertible
- The object to convert and append.IORuntimeException
- if the given output object throws an IOException.public void appendJSONArray(java.lang.Appendable output, java.lang.Object... objects)
objects
- The object array to append.IORuntimeException
- if the given output object throws an IOException.public void appendJSONObject(java.lang.Appendable output, java.lang.Object object)
IORuntimeException
- if the given output object throws an IOException.public void appendJSONMap(java.lang.Appendable output, java.util.Map<java.lang.String,java.lang.Object> map)
IORuntimeException
- if the given output object throws an IOException.public java.lang.String objectToJSONValue(java.lang.Object object)
object
- Any object (even null).public boolean isValidJsonTypeInstance(java.lang.Object object)
Valid types are:
public boolean isValidJsonType(java.lang.Class<?> type)
Valid types are: