com.sdicons.json.model
Class JSONValue

java.lang.Object
  extended by com.sdicons.json.model.JSONValue
Direct Known Subclasses:
JSONComplex, JSONSimple

public abstract class JSONValue
extends Object

Base class for all JSON representations.


Constructor Summary
JSONValue()
           
 
Method Summary
static JSONValue decorate(Object anObject)
          This method is the reverse of a strip, it converts a construction of Java objects to a JSON decorated composition.
 int getCol()
          Get the column number in the textual representation where this JSON value was encountered.
 Object getData()
          Get user data.
 int getLine()
          Get the line number in the textual representation where this JSON value was encountered.
 String getStreamName()
          Get information about the stream in which the value occurred.
 boolean isArray()
          Check if this value represents an array.
 boolean isBoolean()
          Check if this value represents a JSON boolean value.
 boolean isComplex()
          Check if this value represents a "complex" value, meaning: an array, an object.
 boolean isDecimal()
          Check if this value is a decimal.
 boolean isInteger()
          Check if this value is an integer.
 boolean isNull()
          Check if this value represents a JSON null value.
 boolean isNumber()
          Check if this value is a number, meaning: an integer or a decimal.
 boolean isObject()
          Check if this value represents a JSON object.
 boolean isSimple()
          Check if this value represents a "simple" value, meaning: a boolean, a number, a string or null.
 boolean isString()
          Check if this value represents a JSON string.
 String render(boolean pretty)
          Convert the JSON value into a string representation (JSON representation).
protected abstract  String render(boolean pretty, String indent)
          Convert the JSON value into a string representation (JSON representation).
 void setData(Object data)
          Set user data.
 void setLineCol(int line, int col)
          Set The position where this JSON value occurred during parsing.
 void setStreamName(String streamName)
          Fill in information about the stream.
abstract  Object strip()
          This method strips all JSON related information and returns pure Java objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONValue

public JSONValue()
Method Detail

getLine

public int getLine()
Get the line number in the textual representation where this JSON value was encountered. Can be handy for post processing tools which want to give an indication tot he user where in the representation some condition occurred.

Returns:
The line number.

setLineCol

public void setLineCol(int line,
                       int col)
Set The position where this JSON value occurred during parsing. This method is called by the parser. Probably no need to call this yourself.

Parameters:
line -
col -

getStreamName

public String getStreamName()
Get information about the stream in which the value occurred. Its purpose is to identify in which stream the error occurred if multiple streams are being parsed and the error reports are being collected in a single report.

Returns:
The name of the stream.

setStreamName

public void setStreamName(String streamName)
Fill in information about the stream.

Parameters:
streamName -

getCol

public int getCol()
Get the column number in the textual representation where this JSON value was encountered. Can be handy for post processing tools which want to give an indication tot he user where in the representation some condition occurred.

Returns:
The line number.

getData

public Object getData()
Get user data.

Returns:
The user data.

setData

public void setData(Object data)
Set user data. The user of the library can link whatever information is useful in the user context to a JSON object in order to track back to the original JSON data. The JSON tools do not use this field, it is for the user of the library.

Parameters:
data -

isSimple

public boolean isSimple()
Check if this value represents a "simple" value, meaning: a boolean, a number, a string or null.

Returns:
An assertion that the value is "simple".

isComplex

public boolean isComplex()
Check if this value represents a "complex" value, meaning: an array, an object.

Returns:
An assertion that the value is "complex".

isArray

public boolean isArray()
Check if this value represents an array.

Returns:
An assertion that the value is an array.

isObject

public boolean isObject()
Check if this value represents a JSON object.

Returns:
An assertion that the value is a JSON object.

isNumber

public boolean isNumber()
Check if this value is a number, meaning: an integer or a decimal.

Returns:
An assertion that the value is a number.

isDecimal

public boolean isDecimal()
Check if this value is a decimal.

Returns:
An assertion that the value is a decimal.

isInteger

public boolean isInteger()
Check if this value is an integer.

Returns:
An assertion that the value is an integer.

isNull

public boolean isNull()
Check if this value represents a JSON null value.

Returns:
An assertion that the value is the JSON null value.

isBoolean

public boolean isBoolean()
Check if this value represents a JSON boolean value.

Returns:
An assertion that the value is a JSON boolean.

isString

public boolean isString()
Check if this value represents a JSON string.

Returns:
An assertion that the value is a JSON string.

render

public String render(boolean pretty)
Convert the JSON value into a string representation (JSON representation).

Parameters:
pretty - Indicating if the print should be made pretty (human readers) or compact (transmission or storage).
Returns:
A JSON representation.

render

protected abstract String render(boolean pretty,
                                 String indent)
Convert the JSON value into a string representation (JSON representation).

Parameters:
pretty - Indicating if the print should be made pretty (human readers) or compact (transmission or storage).
indent - Starting indent.
Returns:
A JSON representation.

strip

public abstract Object strip()
This method strips all JSON related information and returns pure Java objects. It can be handy if you know in advance which objects to expect or if you already did validation.

Returns:
Pure Java object, stripped of all JSON information.

decorate

public static JSONValue decorate(Object anObject)
This method is the reverse of a strip, it converts a construction of Java objects to a JSON decorated composition.

Parameters:
anObject -
Returns:
A JSONValue representing the object.
Throws:
IllegalArgumentException - If a conversion cannot be done.


Copyright © 2011. All Rights Reserved.