- java.lang.Object
-
- com.speedment.common.json.Json
-
public final class Json extends Object
A utility class that can parse strings into ordinary java objects.JSON is parsed using the
RFC 7159specification.- Since:
- 1.0.0
- Author:
- Emil Forslund
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ObjectfromJson(InputStream in)Parses the specified JSON stream of unicode characters into a java object.static ObjectfromJson(String json)Parses the specified JSON string into a java object.static StringtoJson(Object object)Parses the specified object to a JSON string.static StringtoJson(Object object, boolean pretty)Parses the specified object to JSON and prints it to the specified stream.static voidtoJson(Object object, OutputStream out)Parses the specified object to JSON and prints it to the specified stream.static voidtoJson(Object object, OutputStream out, boolean pretty)Parses the specified object to JSON and prints it to the specified stream.
-
-
-
Method Detail
-
toJson
public static String toJson(Object object)
Parses the specified object to a JSON string. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
This method will output a nicely formatted JSON string (with spaces and new-lines).
- Parameters:
object- the object to parse- Returns:
- the parsed string
- Throws:
IllegalArgumentException- if the input object is a or contains unsupported types
-
toJson
public static String toJson(Object object, boolean pretty)
Parses the specified object to JSON and prints it to the specified stream. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
This method will output a nicely formatted JSON string (with spaces and new-lines).
- Parameters:
object- the object to parsepretty- if the result should be formatted in a pretty way- Returns:
- JSON String
- Throws:
IllegalArgumentException- if the input object is of or contains unsupported types
-
toJson
public static void toJson(Object object, OutputStream out) throws IOException
Parses the specified object to JSON and prints it to the specified stream. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
This method will output a nicely formatted JSON string (with spaces and new-lines).
- Parameters:
object- the object to parseout- the stream to write the result to- Throws:
IllegalArgumentException- if the inputed object is of or contains unsupported typesIOException- if the stream could not be written to
-
toJson
public static void toJson(Object object, OutputStream out, boolean pretty) throws IOException
Parses the specified object to JSON and prints it to the specified stream. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
This method will output a nicely formatted JSON string (with spaces and new-lines).
- Parameters:
object- the object to parseout- the stream to write the result topretty- if the result should be formatted in a pretty way- Throws:
IllegalArgumentException- if the input object is of or contains unsupported typesIOException- if the stream could not be written to
-
fromJson
public static Object fromJson(String json)
Parses the specified JSON string into a java object. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
- Parameters:
json- the json to parse- Returns:
- the created object
- Throws:
JsonSyntaxException- if there is a syntax error
-
fromJson
public static Object fromJson(InputStream in) throws IOException
Parses the specified JSON stream of unicode characters into a java object. The following objects are supported:Map<String, Object>List<Object>StringDoubleLongnull
- Parameters:
in- the json to parse- Returns:
- the created object
- Throws:
IOException- if the stream can not be readJsonSyntaxException- if there is a syntax error
-
-