Package net.minidev.json
Class JSONValue
- java.lang.Object
-
- net.minidev.json.JSONValue
-
public class JSONValue extends java.lang.Object
JSONValue is the helper class In most of case you should use those static methode to user JSON-smart The most commonly use methode areparse(String)
toJSONString(Object)
-
-
Field Summary
Fields Modifier and Type Field Description static JSONStyle
COMPRESSION
Global default compression typestatic JsonReader
defaultReader
deserialisation class Datastatic JsonWriter
defaultWriter
Serialisation class Data
-
Constructor Summary
Constructors Constructor Description JSONValue()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
compress(java.lang.String input)
Compress Json input keeping element orderstatic java.lang.String
compress(java.lang.String input, JSONStyle style)
Reformat Json input keeping element orderstatic java.lang.String
escape(java.lang.String s)
static void
escape(java.lang.String s, java.lang.Appendable ap)
static void
escape(java.lang.String s, java.lang.Appendable ap, JSONStyle compression)
static java.lang.String
escape(java.lang.String s, JSONStyle compression)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).static boolean
isValidJson(java.io.Reader in)
Check Json Syntax from input Readerstatic boolean
isValidJson(java.lang.String s)
Check Json Syntax from input Stringstatic boolean
isValidJsonStrict(java.io.Reader in)
Check RFC4627 Json Syntax from input Readerstatic boolean
isValidJsonStrict(java.lang.String s)
check RFC4627 Json Syntax from input Stringstatic java.lang.Object
parse(byte[] in)
Parse JSON text into java object from the input source.static <T> T
parse(byte[] in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a beanprotected static <T> T
parse(byte[] in, JsonReaderI<T> mapper)
Parse input json as a mapTo classstatic java.lang.Object
parse(java.io.InputStream in)
Parse JSON text into java object from the input source.static <T> T
parse(java.io.InputStream in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a beanstatic <T> T
parse(java.io.InputStream in, T toUpdate)
Parse input json as a mapTo class mapTo can be a beanstatic java.lang.Object
parse(java.io.Reader in)
Parse JSON text into java object from the input source.static <T> T
parse(java.io.Reader in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a beanprotected static <T> T
parse(java.io.Reader in, JsonReaderI<T> mapper)
Parse input json as a mapTo classstatic <T> T
parse(java.io.Reader in, T toUpdate)
Parse input json as a mapTo class mapTo can be a beanstatic java.lang.Object
parse(java.lang.String s)
Parse JSON text into java object from the input source.static <T> T
parse(java.lang.String in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a beanprotected static <T> T
parse(java.lang.String in, JsonReaderI<T> mapper)
Parse input json as a mapTo classstatic <T> T
parse(java.lang.String in, T toUpdate)
Parse input json as a mapTo class mapTo can be a beanstatic java.lang.Object
parseKeepingOrder(java.io.Reader in)
Parse Json input to a java Object keeping element orderstatic java.lang.Object
parseKeepingOrder(java.lang.String in)
Parse Json input to a java Object keeping element orderstatic java.lang.Object
parseStrict(java.io.Reader in)
Parse valid RFC4627 JSON text into java object from the input source.static java.lang.Object
parseStrict(java.lang.String s)
Parse valid RFC4627 JSON text into java object from the input source.static java.lang.Object
parseWithException(byte[] in)
Parse JSON text into java object from the input source.static java.lang.Object
parseWithException(java.io.InputStream in)
Parse JSON text into java object from the input source.static java.lang.Object
parseWithException(java.io.Reader in)
Parse JSON text into java object from the input source.static java.lang.Object
parseWithException(java.lang.String s)
Parse JSON text into java object from the input source.static <T> T
parseWithException(java.lang.String in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a beanstatic <T> void
registerReader(java.lang.Class<T> type, JsonReaderI<T> mapper)
register a deserializer for a class.static <T> void
registerWriter(java.lang.Class<?> cls, JsonWriterI<T> writer)
Register a serializer for a class.static <T> void
remapField(java.lang.Class<T> type, java.lang.String jsonFieldName, java.lang.String javaFieldName)
remap field from java to json.static java.lang.String
toJSONString(java.lang.Object value)
Encode an object into JSON text and write it to out.static java.lang.String
toJSONString(java.lang.Object value, JSONStyle compression)
Convert an object to JSON text.static java.lang.String
uncompress(java.lang.String input)
Compress Json input keeping element orderstatic void
writeJSONString(java.lang.Object value, java.lang.Appendable out)
Encode an object into JSON text and write it to out.static void
writeJSONString(java.lang.Object value, java.lang.Appendable out, JSONStyle compression)
Encode an object into JSON text and write it to out.
-
-
-
Field Detail
-
COMPRESSION
public static JSONStyle COMPRESSION
Global default compression type
-
defaultWriter
public static final JsonWriter defaultWriter
Serialisation class Data
-
defaultReader
public static final JsonReader defaultReader
deserialisation class Data
-
-
Method Detail
-
parse
public static java.lang.Object parse(java.io.InputStream in)
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:
JSONParser.parse(Reader)
,parseWithException(Reader)
-
parse
public static java.lang.Object parse(byte[] in)
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:
JSONParser.parse(Reader)
,parseWithException(Reader)
-
parse
public static <T> T parse(java.io.InputStream in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
public static java.lang.Object parse(java.io.Reader in)
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:
JSONParser.parse(Reader)
,parseWithException(Reader)
-
parse
public static <T> T parse(byte[] in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
public static <T> T parse(java.io.Reader in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
public static <T> T parse(java.io.Reader in, T toUpdate)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
protected static <T> T parse(java.io.Reader in, JsonReaderI<T> mapper)
Parse input json as a mapTo class- Since:
- 2.0
-
parse
public static <T> T parse(java.lang.String in, java.lang.Class<T> mapTo)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
public static <T> T parse(java.io.InputStream in, T toUpdate)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
public static <T> T parse(java.lang.String in, T toUpdate)
Parse input json as a mapTo class mapTo can be a bean- Since:
- 2.0
-
parse
protected static <T> T parse(byte[] in, JsonReaderI<T> mapper)
Parse input json as a mapTo class- Since:
- 2.0
-
parse
protected static <T> T parse(java.lang.String in, JsonReaderI<T> mapper)
Parse input json as a mapTo class- Since:
- 2.0
-
parse
public static java.lang.Object parse(java.lang.String s)
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:
JSONParser.parse(String)
,parseWithException(String)
-
parseKeepingOrder
public static java.lang.Object parseKeepingOrder(java.io.Reader in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.6.1
-
parseKeepingOrder
public static java.lang.Object parseKeepingOrder(java.lang.String in)
Parse Json input to a java Object keeping element order- Since:
- 1.0.6.1
-
compress
public static java.lang.String compress(java.lang.String input, JSONStyle style)
Reformat Json input keeping element order- Since:
- 1.0.6.2 need to be rewrite in 2.0
-
compress
public static java.lang.String compress(java.lang.String input)
Compress Json input keeping element order- Since:
- 1.0.6.1 need to be rewrite in 2.0
-
uncompress
public static java.lang.String uncompress(java.lang.String input)
Compress Json input keeping element order- Since:
- 1.0.6.1
-
parseWithException
public static java.lang.Object parseWithException(byte[] in) throws java.io.IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
java.io.IOException
ParseException
- See Also:
JSONParser
-
parseWithException
public static java.lang.Object parseWithException(java.io.InputStream in) throws java.io.IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
java.io.IOException
ParseException
- See Also:
JSONParser
-
parseWithException
public static java.lang.Object parseWithException(java.io.Reader in) throws java.io.IOException, ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
java.io.IOException
ParseException
- See Also:
JSONParser
-
parseWithException
public static java.lang.Object parseWithException(java.lang.String s) throws ParseException
Parse JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException
- See Also:
JSONParser
-
parseWithException
public static <T> T parseWithException(java.lang.String in, java.lang.Class<T> mapTo) throws ParseException
Parse input json as a mapTo class mapTo can be a bean- Throws:
ParseException
- Since:
- 2.0
-
parseStrict
public static java.lang.Object parseStrict(java.io.Reader in) throws java.io.IOException, ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
java.io.IOException
ParseException
- See Also:
JSONParser
-
parseStrict
public static java.lang.Object parseStrict(java.lang.String s) throws ParseException
Parse valid RFC4627 JSON text into java object from the input source.- Returns:
- Instance of the following: JSONObject, JSONArray, String, java.lang.Number, java.lang.Boolean, null
- Throws:
ParseException
- See Also:
JSONParser
-
isValidJsonStrict
public static boolean isValidJsonStrict(java.io.Reader in) throws java.io.IOException
Check RFC4627 Json Syntax from input Reader- Returns:
- if the input is valid
- Throws:
java.io.IOException
-
isValidJsonStrict
public static boolean isValidJsonStrict(java.lang.String s)
check RFC4627 Json Syntax from input String- Returns:
- if the input is valid
-
isValidJson
public static boolean isValidJson(java.io.Reader in) throws java.io.IOException
Check Json Syntax from input Reader- Returns:
- if the input is valid
- Throws:
java.io.IOException
-
isValidJson
public static boolean isValidJson(java.lang.String s)
Check Json Syntax from input String- Returns:
- if the input is valid
-
writeJSONString
public static void writeJSONString(java.lang.Object value, java.lang.Appendable out) throws java.io.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:
java.io.IOException
- See Also:
JSONObject.writeJSON(Map, Appendable)
,JSONArray.writeJSONString(List, Appendable)
-
remapField
public static <T> void remapField(java.lang.Class<T> type, java.lang.String jsonFieldName, java.lang.String javaFieldName)
remap field from java to json.- Since:
- 2.1.1
-
registerWriter
public static <T> void registerWriter(java.lang.Class<?> cls, JsonWriterI<T> writer)
Register a serializer for a class.
-
registerReader
public static <T> void registerReader(java.lang.Class<T> type, JsonReaderI<T> mapper)
register a deserializer for a class.
-
writeJSONString
public static void writeJSONString(java.lang.Object value, java.lang.Appendable out, JSONStyle compression) throws java.io.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:
java.io.IOException
- See Also:
JSONObject.writeJSON(Map, Appendable)
,JSONArray.writeJSONString(List, Appendable)
-
toJSONString
public static java.lang.String toJSONString(java.lang.Object value)
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.
-
toJSONString
public static java.lang.String toJSONString(java.lang.Object value, JSONStyle compression)
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.
- Returns:
- JSON text, or "null" if value is null or it's an NaN or an INF number.
- See Also:
JSONObject.toJSONString(Map)
,JSONArray.toJSONString(List)
-
escape
public static java.lang.String escape(java.lang.String s)
-
escape
public static java.lang.String escape(java.lang.String s, JSONStyle compression)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).
-
escape
public static void escape(java.lang.String s, java.lang.Appendable ap)
-
escape
public static void escape(java.lang.String s, java.lang.Appendable ap, JSONStyle compression)
-
-