- java.lang.Object
-
- org.shredzone.acme4j.toolbox.JSON
-
- All Implemented Interfaces:
Serializable
public final class JSON extends Object implements Serializable
A model containing a JSON result. The content is immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSON.Array
Represents a JSON array.static class
JSON.Value
A single JSON value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(String key)
Checks if this object contains the given key.static JSON
empty()
Returns aJSON
of an empty document.static JSON
fromMap(Map<String,Object> data)
Creates a JSON object from a map.JSON.Value
get(String key)
Returns theJSON.Value
of the given key.JSON.Value
getFeature(String key)
Returns theJSON.Value
of the given key.Set<String>
keySet()
Returns a set of all keys of this object.static JSON
parse(InputStream in)
Parses JSON from anInputStream
.static JSON
parse(String json)
Parses JSON from a String.Map<String,Object>
toMap()
Returns the content as unmodifiable Map.String
toString()
Returns the content as JSON string.
-
-
-
Method Detail
-
parse
public static JSON parse(InputStream in) throws IOException
Parses JSON from anInputStream
.- Parameters:
in
-InputStream
to read from. Will be closed after use.- Returns:
JSON
of the read content.- Throws:
IOException
-
parse
public static JSON parse(String json)
Parses JSON from a String.- Parameters:
json
- JSON string- Returns:
JSON
of the read content.
-
fromMap
public static JSON fromMap(Map<String,Object> data)
Creates a JSON object from a map.The map's content is deeply copied. Changes to the map won't reflect in the created JSON structure.
- Parameters:
data
- Map structure- Returns:
JSON
of the map's content.- Since:
- 3.2.0
-
contains
public boolean contains(String key)
Checks if this object contains the given key.- Parameters:
key
- Name of the key to check- Returns:
true
if the key is present
-
get
public JSON.Value get(String key)
Returns theJSON.Value
of the given key.- Parameters:
key
- Key to read- Returns:
JSON.Value
of the key
-
getFeature
public JSON.Value getFeature(String key)
Returns theJSON.Value
of the given key.- Parameters:
key
- Key to read- Returns:
JSON.Value
of the key- Throws:
AcmeNotSupportedException
- if the key is not present. The key is used as feature name.
-
-