Package org.drip.service.representation
Class JSONObject
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap
org.drip.service.representation.JSONObject
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map
,JSONAware
,JSONStreamAware
public class JSONObject extends java.util.HashMap implements java.util.Map, JSONAware, JSONStreamAware
JSONObject is an Adaptation of the JSONObject Class from the RFC4627 compliant JSON Simple
(https://code.google.com/p/json-simple/). It provides the following Functionality:
- Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F). It's the same as JSONValue.escape() only for compatibility here
- Encode a map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware, or JSONStreamAware specific behavior will be ignored at this top level
- Convert a map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behavior will be omitted at this top level
- Encode "this" map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware, or JSONStreamAware specific behavior will be ignored at this top level
- Convert "this" map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behavior will be omitted at this top level
- Convert "this" to JSON text - this directly defers to JSON'izer
Module | Computational Core Module |
Library | Computation Support |
Project | Environment, Product/Definition Containers, and Scenario/State Manipulation APIs |
Package | RFC4627 Compliant JSON Message Object |
- Author:
- Fang Yidong, Lakshmi Krishnamurthy
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,V extends java.lang.Object>
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
Constructor Summary
Constructors Constructor Description JSONObject()
Empty JSONObject Constructor JSONize the key-value String Empty JSONObject Constructor Allows creation of a JSONObject from a Map.JSONObject(java.util.Map map)
Allows creation of a JSONObject from a Map. -
Method Summary
Modifier and Type Method Description static java.lang.String
escape(java.lang.String s)
Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F).java.lang.String
toJSONString()
Convert "this" map to JSON text.static java.lang.String
toJSONString(java.util.Map map)
Convert a map to JSON text.java.lang.String
toString()
Convert "this" to JSON text - this directly defers to JSON'izerstatic java.lang.String
toString(java.lang.String key, java.lang.Object value)
JSONize the key-value Stringvoid
writeJSONString(java.io.Writer outputWriter)
Encode "this" map into JSON text and write it to out.static void
writeJSONString(java.util.Map map, java.io.Writer outputWriter)
Encode a map into JSON text and write it to out.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
JSONObject
public JSONObject()Empty JSONObject Constructor JSONize the key-value String Empty JSONObject Constructor Allows creation of a JSONObject from a Map. After that, both the generated JSONObject and the Map can be modified independently. Encode "this" map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware, or JSONStreamAware specific behavior will be ignored at this top level. -
JSONObject
public JSONObject(java.util.Map map)Allows creation of a JSONObject from a Map. After that, both the generated JSONObject and the Map can be modified independently.- Parameters:
map
- Input JSON Map
-
-
Method Details
-
escape
public static java.lang.String escape(java.lang.String s)Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F). It's the same as JSONValue.escape() only for compatibility here.- Parameters:
s
- The Input String- Returns:
- Escaped String
- See Also:
JSONValue.escape(String)
-
writeJSONString
public static void writeJSONString(java.util.Map map, java.io.Writer outputWriter) throws java.io.IOExceptionEncode a map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware, or JSONStreamAware specific behavior will be ignored at this top level.- Parameters:
map
- Input MapoutputWriter
- Output Writer- Throws:
java.io.IOException
- Thrown if the Inputs are Invalid- See Also:
JSONValue.writeJSONString(Object, Writer)
-
toJSONString
public static java.lang.String toJSONString(java.util.Map map)Convert a map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behavior will be omitted at this top level.- Parameters:
map
- The JSON Map- Returns:
- JSON text, or "null" if map is null.
- See Also:
JSONValue.toJSONString(Object)
-
toString
public static java.lang.String toString(java.lang.String key, java.lang.Object value)JSONize the key-value String- Parameters:
key
- Keyvalue
- Value- Returns:
- The JSONized Key-Value String
-
writeJSONString
public void writeJSONString(java.io.Writer outputWriter) throws java.io.IOExceptionEncode "this" map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware, or JSONStreamAware specific behavior will be ignored at this top level.- Specified by:
writeJSONString
in interfaceJSONStreamAware
- Parameters:
outputWriter
- Output Writer- Throws:
java.io.IOException
- Thrown if the Inputs are Invalid- See Also:
JSONValue.writeJSONString(Object, Writer)
-
toJSONString
public java.lang.String toJSONString()Convert "this" map to JSON text. The result is a JSON object. If this map is also a JSONAware, JSONAware specific behavior will be omitted at this top level.- Specified by:
toJSONString
in interfaceJSONAware
- Returns:
- JSON text, or "null" if map is null.
- See Also:
JSONValue.toJSONString(Object)
-
toString
public java.lang.String toString()Convert "this" to JSON text - this directly defers to JSON'izer- Overrides:
toString
in classjava.util.AbstractMap
- Returns:
- JSON text, or "null" if map is null.
- See Also:
JSONValue.toJSONString(Object)
-