com.planet_ink.coffee_mud.core
Class MiniJSON

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.MiniJSON

public class MiniJSON
extends java.lang.Object

A JSON parser. Not much to say. It can take a valid json string and generate a standing object that represents the document string, and also generate a string from such an object.


Nested Class Summary
static class MiniJSON.JSONObject
          An official JSON object.
static class MiniJSON.MJSONException
          An official MiniJSON parsing exception.
 
Field Summary
static java.lang.Object NULL
          The official definition of "null" for a JSON object
 
Constructor Summary
MiniJSON()
           
 
Method Summary
 void fromJSONtoPOJO(MiniJSON.JSONObject jsonObj, java.lang.Object o)
          Converts a json object to a pojo object.
 void fromJSONtoPOJO(java.lang.String json, java.lang.Object o)
          Converts a JSON document to a pojo object.
 java.lang.String fromPOJOFieldtoJSON(java.lang.Class<?> type, java.lang.Object val)
          Converts a pojo field to a JSON value.
 java.lang.String fromPOJOtoJSON(java.lang.Object o)
          Converts a pojo object to a JSON document.
 MiniJSON.JSONObject parseObject(java.lang.String doc)
          Given a string containing a JSON object, this method will parse it into a mapped JSONObject object recursively.
static java.lang.String toJSONString(java.lang.String value)
          Given a normal string, this method will return a JSON-Safe string, which means escaped crlf, escaped tabs and backslashes, etc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL

public static final java.lang.Object NULL
The official definition of "null" for a JSON object

Constructor Detail

MiniJSON

public MiniJSON()
Method Detail

toJSONString

public static java.lang.String toJSONString(java.lang.String value)
Given a normal string, this method will return a JSON-Safe string, which means escaped crlf, escaped tabs and backslashes, etc.

Parameters:
value - the unsafe string
Returns:
the JSON safe string

parseObject

public MiniJSON.JSONObject parseObject(java.lang.String doc)
                                throws MiniJSON.MJSONException
Given a string containing a JSON object, this method will parse it into a mapped JSONObject object recursively.

Parameters:
doc - the JSON document that contains a top-level JSON object
Returns:
the JSON object at the top level
Throws:
MiniJSON.MJSONException - the parse error

fromPOJOFieldtoJSON

public java.lang.String fromPOJOFieldtoJSON(java.lang.Class<?> type,
                                            java.lang.Object val)
Converts a pojo field to a JSON value.

Parameters:
type - the class type
val - the value
Returns:
the json value

fromPOJOtoJSON

public java.lang.String fromPOJOtoJSON(java.lang.Object o)
Converts a pojo object to a JSON document.

Parameters:
o - the object to convert
Returns:
the json document

fromJSONtoPOJO

public void fromJSONtoPOJO(java.lang.String json,
                           java.lang.Object o)
                    throws MiniJSON.MJSONException
Converts a JSON document to a pojo object.

Parameters:
json - the json document
o - the object to convert
Throws:
MiniJSON.MJSONException

fromJSONtoPOJO

public void fromJSONtoPOJO(MiniJSON.JSONObject jsonObj,
                           java.lang.Object o)
                    throws MiniJSON.MJSONException
Converts a json object to a pojo object.

Parameters:
jsonObj - the json object
o - the object to convert
Throws:
MiniJSON.MJSONException