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/).

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
    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()  
    static java.lang.String toJSONString​(java.util.Map map)
    Convert a map to JSON text.
    java.lang.String toString()  
    static java.lang.String toString​(java.lang.String key, java.lang.Object value)
    JSONize the key-value String
    void writeJSONString​(java.io.Writer out)
    write JSON string to out.
    static void writeJSONString​(java.util.Map map, java.io.Writer out)
    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
    • 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

    • writeJSONString

      public static void writeJSONString​(java.util.Map map, java.io.Writer out) throws java.io.IOException
      Encode a map into JSON text and write it to out. If this map is also a JSONAware or JSONStreamAware, JSONAware or JSONStreamAware specific behaviours will be ignored at this top level.
      Parameters:
      map - Input Map
      out - Output Writer
      Throws:
      java.io.IOException - Thrown if the Inputs are Invalid
      See Also:
      JSONValue.writeJSONString(Object, Writer)
    • writeJSONString

      public void writeJSONString​(java.io.Writer out) throws java.io.IOException
      Description copied from interface: JSONStreamAware
      write JSON string to out.
      Specified by:
      writeJSONString in interface JSONStreamAware
      Parameters:
      out - Output Writer
      Throws:
      java.io.IOException - Thrown if the Inputs are invalid
    • 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 behaviours 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)
    • toJSONString

      public java.lang.String toJSONString()
      Specified by:
      toJSONString in interface JSONAware
      Returns:
      JSON text
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.util.AbstractMap
    • toString

      public static java.lang.String toString​(java.lang.String key, java.lang.Object value)
      JSONize the key-value String
      Parameters:
      key - Key
      value - Value
      Returns:
      The JSONized Key-Value String
    • 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)