Package org.ka2ddo.yaac.util
Class Json
java.lang.Object
org.ka2ddo.yaac.util.Json
This class is a limited-function decoder and encoder for JSON messages, sufficient to
support the implementation used by gpsd.
- Author:
- Andrew Pavlin, KA2DDO
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A LinkedHashMap intended to hold JSON-structured data, with aJson.JsonHashMap.toString()
method that produces JSON text. -
Method Summary
Modifier and TypeMethodDescriptiondecodeJSON
(Reader din, PortConnector portConnector) Read a JSON object hierarchy from the specified text Reader.static void
encodeJSON
(Map<String, Object> data, PrintWriter pw) Convert a JSON object hierarchy into a JavaScript-compatible string in JSON syntax.
-
Method Details
-
decodeJSON
public static Map<String,Object> decodeJSON(Reader din, PortConnector portConnector) throws IOException Read a JSON object hierarchy from the specified text Reader.- Parameters:
din
- Reader to get the JSON hierarchy fromportConnector
- PortConnector to inform of starting and ending reading a JSON object, or null if no one is to be informed- Returns:
- a Map of JSON attribute names to attribute values (note that some values can be other maps representing sub-ordinate JSON objects)
- Throws:
IOException
- if the Reader cannot be read to the end of the JSON object
-
encodeJSON
Convert a JSON object hierarchy into a JavaScript-compatible string in JSON syntax.- Parameters:
data
- the top object in the JSON hierarchy, represented as a Map with attribute name keys and attribute valuespw
- PrintWriter to write the generated string representation to
-