cc.plural.jsonij
Class JSON

java.lang.Object
  extended by cc.plural.jsonij.JSON

public class JSON
extends Object

JSON document class. This class defines the representation of each of the JSON types and provides methods to parse and create JSON instances from various sources. All JSON types extend Value. The following table documents which class to use when representing each of the JSON types.

JSON Type Class
Object JSON.Object
Array JSON.Array
String JSON.String
Numeric JSON.Numeric
True JSON.TRUE
False JSON.FALSE
Null JSON.NULL

Version:
1.0.0
Author:
J.W.Marsden

Nested Class Summary
static class JSON.Array<E extends Value>
          JSON Array.
static class JSON.Boolean
          JSON Boolean.
static class JSON.False
          JSON False Implementation.
static class JSON.Null
          JSON Null Implementation.
static class JSON.Numeric
          JSON Numeric.
static class JSON.Object<K extends CharSequence,V extends Value>
          JSON Object.
static class JSON.String
          JSON String.
static class JSON.True
          JSON True Implementation.
 
Field Summary
static JSON.False FALSE
          Static Instance holding the JSON False instance.
static JSON.Null NULL
          Static Instance holding the JSON Null instance.
static JSON.True TRUE
          Static Instance holding the JSON True instance.
 
Constructor Summary
JSON(Value root)
          Default JSON constructor.
 
Method Summary
 boolean equals(Object o)
           
 Value get(int i)
          Value accessor by index for the root JSON Value.
 Value get(String key)
          Value accessor by String for the root JSON Value.
 boolean getBoolean()
          Boolean accessor for the root JSON Value.
 double getDouble()
          Double accessor for the root JSON Value.
 int getInt()
          Integer accessor for the root JSON Value.
 Value getRoot()
          Accessor for the root value for this JSON Document.
 String getString()
          String accessor for the root JSON Value.
 int hashCode()
           
 boolean isNull()
          Null check for the root JSON Value.
static JSON parse(Reader documentReader)
          Parse Method that parses from a Reader.
static JSON parse(String document)
          Parse Method that parses from a String.
 int size()
          Size inspector for the root JSON Value.
 String toJSON()
          Converts JSON Document into a valid JSON String.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static final JSON.True TRUE
Static Instance holding the JSON True instance. Reference this instead of constructing new JSON.True instances.


FALSE

public static final JSON.False FALSE
Static Instance holding the JSON False instance. Reference this instead of constructing new JSON.False instances.


NULL

public static final JSON.Null NULL
Static Instance holding the JSON Null instance. Reference this instead of constructing new JSON.Null instances.

Constructor Detail

JSON

public JSON(Value root)
Default JSON constructor. Requires the JSON root Value.

Parameters:
root -
Method Detail

getRoot

public Value getRoot()
Accessor for the root value for this JSON Document.

Returns:
The root Value.

size

public int size()
Size inspector for the root JSON Value. If the root is an object or an array this will return the dimension.

Returns:
The size of the root JSON Value.
See Also:
openecho.json.Value#size()

isNull

public boolean isNull()
Null check for the root JSON Value.

Returns:
Boolean if the root value is JSON.Null.
See Also:
openecho.json.Value#isNull()

getBoolean

public boolean getBoolean()
Boolean accessor for the root JSON Value.

Returns:
Boolean Value for the root JSON Value.
See Also:
openecho.json.Value#getBoolean()

getInt

public int getInt()
Integer accessor for the root JSON Value.

Returns:
int Value for the root JSON Value.
See Also:
openecho.json.Value#getInt()

getDouble

public double getDouble()
Double accessor for the root JSON Value.

Returns:
double Value for the root JSON Value.
See Also:
openecho.json.Value#getDouble()

getString

public String getString()
String accessor for the root JSON Value.

Returns:
java.lang.String Value for the root JSON Value.
See Also:
openecho.json.Value#getString()

get

public Value get(int i)
Value accessor by index for the root JSON Value.

Parameters:
i - The index to access.
Returns:
Value Value for the root JSON Value.
See Also:
openecho.json.Value#get(int i)

get

public Value get(String key)
Value accessor by String for the root JSON Value. This method only functions if the root value is a JSON Object.

Parameters:
key - The key to access.
Returns:
Value Value for the root JSON Value.
See Also:
openecho.json.Value#get(java.lang.String key)

toJSON

public String toJSON()
Converts JSON Document into a valid JSON String.

Returns:
The JSON String.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

parse

public static JSON parse(String document)
                  throws ParserException,
                         IOException
Parse Method that parses from a String.

Parameters:
document - The document.
Returns:
Parsed JSON instance.
Throws:
ParserException - JSON Parser Exception.
IOException - IO Exception.

parse

public static JSON parse(Reader documentReader)
                  throws ParserException,
                         IOException
Parse Method that parses from a Reader. The messageReader should be reset.

Parameters:
documentReader - The Reader parameter.
Returns:
Parsed JSON instance.
Throws:
ParserException - JSON Parser Exception.
IOException - IO Exception.


Copyright © 2012. All Rights Reserved.