Package com.sdicons.json.model
Class JSONValue
java.lang.Object
com.sdicons.json.model.JSONValue
- Direct Known Subclasses:
JSONComplex
,JSONSimple
Base class for all JSON representations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JSONValue
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.getData()
Get user data.int
getLine()
Get the line number in the textual representation where this JSON value was encountered.Get information about the stream in which the value occurred.boolean
isArray()
Check if this value represents an array.boolean
Check if this value represents a JSON boolean value.boolean
Check if this value represents a "complex" value, meaning: an array, an object.boolean
Check if this value is a decimal.boolean
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.render
(boolean pretty) Convert the JSON value into a string representation (JSON representation).protected abstract String
Convert the JSON value into a string representation (JSON representation).void
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.
-
Field Details
-
streamName
-
line
private int line -
col
private int col -
data
-
-
Constructor Details
-
JSONValue
public JSONValue()
-
-
Method Details
-
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
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
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
Get user data.- Returns:
- The user data.
-
setData
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
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
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
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
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.
-