Package net.minidev.json
Class JSONValue
java.lang.Object
net.minidev.json.JSONValue
JSONValue is the helper class In most of case you should use those static
method to user JSON-smart
The most commonly use method are
parse(String)
toJSONString(Object)- Author:
- Uriel Chemouni <uchemouni@gmail.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic JSONStyleGlobal default compression typestatic final JsonReaderdeserialisation class Datastatic final JsonWriterSerialisation class Data -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCompress Json input keeping element orderstatic StringReformat Json input keeping element orderstatic Stringstatic voidescape(String s, Appendable ap) static voidescape(String s, Appendable ap, JSONStyle compression) static StringEscape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).static booleanisValidJson(Reader in) Check Json Syntax from input Readerstatic booleanCheck Json Syntax from input Stringstatic booleanCheck RFC4627 Json Syntax from input Readerstatic booleancheck RFC4627 Json Syntax from input Stringstatic Objectparse(byte[] in) Parse JSON text into java object from the input source.static <T> TParse input json as a mapTo class mapTo can be a beanprotected static <T> Tparse(byte[] in, JsonReaderI<T> mapper) Parse input json as a mapTo classstatic Objectparse(InputStream in) Parse JSON text into java object from the input source.static <T> Tparse(InputStream in, Class<T> mapTo) Parse input json as a mapTo class mapTo can be a beanstatic <T> Tparse(InputStream in, T toUpdate) Parse input json as a mapTo class mapTo can be a beanstatic ObjectParse JSON text into java object from the input source.static <T> TParse input json as a mapTo class mapTo can be a beanprotected static <T> Tparse(Reader in, JsonReaderI<T> mapper) Parse input json as a mapTo classstatic <T> TParse input json as a mapTo class mapTo can be a beanstatic ObjectParse JSON text into java object from the input source.static <T> TParse input json as a mapTo class mapTo can be a beanprotected static <T> Tparse(String in, JsonReaderI<T> mapper) Parse input json as a mapTo classstatic <T> TParse input json as a mapTo class mapTo can be a beanstatic ObjectParse Json input to a java Object keeping element orderstatic ObjectParse Json input to a java Object keeping element orderstatic ObjectparseStrict(Reader in) Parse valid RFC4627 JSON text into java object from the input source.static ObjectParse valid RFC4627 JSON text into java object from the input source.static ObjectparseWithException(byte[] in) Parse JSON text into java object from the input source.static ObjectParse JSON text into java object from the input source.static ObjectParse JSON text into java object from the input source.static ObjectparseWithException(String input) Parse JSON text into java object from the input source.static <T> TparseWithException(String in, Class<T> mapTo) Parse input json as a mapTo classstatic <T> voidregisterReader(Class<T> type, JsonReaderI<T> mapper) register a deserializer for a class.static <T> voidregisterWriter(Class<?> cls, JsonWriterI<T> writer) Register a serializer for a class.static <T> voidremapField(Class<T> type, String jsonFieldName, String javaFieldName) Remap field from java to json, useful to avoid protected keyword in java class.static StringtoJSONString(Object value) Encode an object into JSON text and write it to out.static StringtoJSONString(Object value, JSONStyle compression) Convert an object to JSON text.static Stringuncompress(String input) Compress Json input keeping element orderstatic voidwriteJSONString(Object value, Appendable out) Encode an object into JSON text and write it to out.static voidwriteJSONString(Object value, Appendable out, JSONStyle compression) Encode an object into JSON text and write it to out.
-
Field Details
-
COMPRESSION
Global default compression type -
defaultWriter
Serialisation class Data -
defaultReader
deserialisation class Data
-
-
Constructor Details
-
JSONValue
public JSONValue()
-
-
Method Details
-
parse
Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- See Also:
-
parse
Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- See Also:
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- See Also:
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class- Since:
- 2.0
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
Parse input json as a mapTo class- Since:
- 2.0
-
parse
Parse input json as a mapTo class- Since:
- 2.0
-
parse
Parse JSON text into java object from the input source. Please use parseWithException() if you don't want to ignore the exception. if you want strict input check use parseStrict()- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- See Also:
-
parseKeepingOrder
Parse Json input to a java Object keeping element order- Parameters:
in- json source- Returns:
- a OrderedMap preserving field order.
- Since:
- 1.0.6.1
-
parseKeepingOrder
Parse Json input to a java Object keeping element order- Parameters:
in- json source- Returns:
- a OrderedMap preserving field order.\
- Since:
- 1.0.6.1
-
compress
Reformat Json input keeping element order- Parameters:
input- text to parsestyle- parse options- Returns:
- json string
- Since:
- 1.0.6.2
-
compress
Compress Json input keeping element order- Parameters:
input- text to parse- Since:
- 1.0.6.1 need to be rewrite in 2.0
-
uncompress
Compress Json input keeping element order- Parameters:
input- text to parse- Since:
- 1.0.6.1
-
parseWithException
Parse JSON text into java object from the input source.- Parameters:
in- source to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
-
parseWithException
Parse JSON text into java object from the input source.- Parameters:
in- source to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
-
parseWithException
Parse JSON text into java object from the input source.- Parameters:
in- source to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
-
parseWithException
Parse JSON text into java object from the input source.- Parameters:
input- string to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- if input in invalid- See Also:
-
parseWithException
Parse input json as a mapTo class- Parameters:
in- source to parsemapTo- destination type, mapTo can be a javabean- Returns:
- unserialized object of type mapTo
- Throws:
ParseException- Since:
- 2.0
-
parseStrict
Parse valid RFC4627 JSON text into java object from the input source.- Parameters:
in- source to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
IOExceptionParseException- See Also:
-
parseStrict
Parse valid RFC4627 JSON text into java object from the input source.- Parameters:
s- source to parse- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException- See Also:
-
isValidJsonStrict
Check RFC4627 Json Syntax from input Reader- Returns:
- if the input is valid
- Throws:
IOException
-
isValidJsonStrict
check RFC4627 Json Syntax from input String- Returns:
- if the input is valid
-
isValidJson
Check Json Syntax from input Reader- Returns:
- if the input is valid
- Throws:
IOException
-
isValidJson
Check Json Syntax from input String- Returns:
- if the input is valid
-
writeJSONString
Encode an object into JSON text and write it to out.If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.
- Throws:
IOException- See Also:
-
remapField
Remap field from java to json, useful to avoid protected keyword in java class.- Parameters:
type- type to alterjsonFieldName- field name in jsonjavaFieldName- field name in java- Since:
- 2.1.1
-
registerWriter
Register a serializer for a class. -
registerReader
register a deserializer for a class. -
writeJSONString
public static void writeJSONString(Object value, Appendable out, JSONStyle compression) throws IOException Encode an object into JSON text and write it to out.If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.
- Throws:
IOException- See Also:
-
toJSONString
Encode an object into JSON text and write it to out.If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly.
- Parameters:
value- object to serialize- Returns:
- json string
- See Also:
-
toJSONString
Convert an object to JSON text.If this object is a Map or a List, and it's also a JSONAware, JSONAware will be considered firstly.
DO NOT call this method from toJSONString() of a class that implements both JSONAware and Map or List with "this" as the parameter, use JSONObject.toJSONString(Map) or JSONArray.toJSONString(List) instead.
- Parameters:
value- to serializecompression- serialisation options- Returns:
- JSON text, or "null" if value is null or it's an NaN or an INF number.
- See Also:
-
escape
-
escape
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).- Parameters:
s- string to escapecompression- compression options- Returns:
- escaped string
-
escape
-
escape
-