EZ JSON
by Nathanaël Cottin

org.ezjson
Class JSONDecoder

java.lang.Object
  extended by org.ezjson.JSONDecoder

public final class JSONDecoder
extends java.lang.Object

Default JSON objects serialized form parser

Author:
ncottin

Constructor Summary
JSONDecoder()
           
 
Method Summary
static JSONObject decode(java.io.BufferedReader in)
          Generates a JSON object from a source stream
static JSONBoolean getAsBoolean(JSONValue value)
          Attempts to get a JSON boolean from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown.
static JSONInteger getAsInteger(JSONValue value)
          Attempts to get a JSON integer from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown.
static JSONNumber getAsNumber(JSONValue value)
          Attempts to get a JSON number from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown.
static JSONReal getAsReal(JSONValue value)
          Attempts to get a JSON real from any JSON value (usually a JSON string or a JSON integer) when the actual type of this JSON value is unknown.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONDecoder

public JSONDecoder()
Method Detail

decode

public static JSONObject decode(java.io.BufferedReader in)
                         throws java.io.IOException,
                                JSONDecodingException
Generates a JSON object from a source stream

Parameters:
in - The non-nul source reader which contains a JSON encoded object
Returns:
The decoded JSON object from the source reader
Throws:
java.io.IOException - The decoder could not access the reader content
JSONDecodingException - The source content does not conform to a valid JSON encoding

getAsBoolean

public static JSONBoolean getAsBoolean(JSONValue value)
                                throws JSONDecodingException
Attempts to get a JSON boolean from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown. This operation is useful when a decoded JSON object may hold JSON strings instead of JSON booleans (i.e. when encoded boolean values are represented between double quotes, this decoder decodes as JSON strings). Note that this operation is not required when the default encoder is used...

Parameters:
value - A possibly null value (mostly obtained from a decoded JSON object)
Returns:
The given value if this value is a JSON boolean or null, or the corresponding JSON boolean, which equals true only when the provided value is a JSON string which equals "true"
Throws:
JSONDecodingException - The non-null provided value does not represent a boolean value

getAsNumber

public static JSONNumber getAsNumber(JSONValue value)
                              throws JSONDecodingException
Attempts to get a JSON number from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown. This operation is useful when a decoded JSON object may hold JSON strings instead of JSON numbers (i.e. when encoded numbers are represented between double quotes, this decoder decodes as JSON strings). Note that this operation is not required when the default encoder is used...

Parameters:
value - A possibly null value (mostly obtained from a decoded JSON object)
Returns:
The corresponding JSON number (i.e. integer or real) or null in case the provided value is null. The actual type can be determined by means of JSONNumber.isInteger()
Throws:
JSONDecodingException - The non-null provided value does not represent a number value

getAsInteger

public static JSONInteger getAsInteger(JSONValue value)
                                throws JSONDecodingException
Attempts to get a JSON integer from any JSON value (usually a JSON string) when the actual type of this JSON value is unknown. This operation is useful when a decoded JSON object may hold JSON strings instead of JSON numbers (i.e. when encoded integers are represented between double quotes, this decoder decodes as JSON strings). Note that this operation is not required when the default encoder is used...

Parameters:
value - A possibly null value (mostly obtained from a decoded JSON object)
Returns:
The corresponding JSON integer or null in case the provided value is null
Throws:
JSONDecodingException - The non-null provided value does not represent an integer value

getAsReal

public static JSONReal getAsReal(JSONValue value)
                          throws JSONDecodingException
Attempts to get a JSON real from any JSON value (usually a JSON string or a JSON integer) when the actual type of this JSON value is unknown. This operation is useful when a decoded JSON object may hold JSON strings or integers instead of JSON reals (i.e. when encoded reals are represented by strings - between double quotes - or by integer values), this decoder respectively decodes as JSON strings or JSON integer). Note that this operation is not required when the default encoder is used...

Parameters:
value - A possibly null value (mostly obtained from a decoded JSON object)
Returns:
The corresponding JSON real or null in case the provided value is null
Throws:
JSONDecodingException - The non-null provided value does not represent a real value

EZ JSON
by Nathanaël Cottin