Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public class JSONValueFactory
- Object
- JSONValueFactory
Builds the values JSONParser.parseStrict(String, JSONValueFactory) reads.
The strict reader calls these methods as it walks a document, and whatever they return is what the containers hold, so a caller can parse straight into its own types instead of converting a tree of maps and lists afterwards. A language runtime builds its own dictionaries and numbers this way, and a data binder can build its objects without a second pass.
This class answers exactly what JSONParser.parseStrict(String) answers: a
LinkedHashMap per object, an ArrayList per array, String, Boolean,
null, Long for an integer and Double for any other number. Override the
methods whose result should differ. Containers are opened, filled in document
order and closed; a value is complete when it is handed to its parent.
Two relaxations of RFC 8259 are off unless a subclass turns them on:
allowNonFinite() for NaN, Infinity, -Infinity and numbers too large
for a double, and allowControlCharacters() for unescaped control
characters inside strings.
Constructors
public JSONValueFactory() |
Methods
Inherited methods
Constructor details
JSONValueFactory
public JSONValueFactory()Method details
newObject
public Object newObject()Returns
put(Object, String, Object)
and endObject(Object)put
public void put(Object object, String key, Object value)newObject(). A key may repeat;
the reader passes every occurrence in order.Parameters
objectObject- the container
keyString- the member name
valueObject- the member value
endObject
public Object endObject(Object object)Parameters
objectObject- the container
Returns
newArray
public Object newArray()Returns
add
public void add(Object array, Object value)newArray().Parameters
arrayObject- the container
valueObject- the element
endArray
public Object endArray(Object array)Parameters
arrayObject- the container
Returns
string
public Object string(String value)Parameters
valueString- the decoded string
Returns
integer
public Object integer(long value)long.Parameters
valuelong- the integer
Returns
bigInteger
public Object bigInteger(String digits)
throws IOExceptionlong.Parameters
digitsString- the integer as written, with its sign
Returns
Throws
IOException- to refuse it, which this class does
decimal
public Object decimal(double value)allowNonFinite() is on.Parameters
valuedouble- the number
Returns
bool
public Object bool(boolean value)true or false.Parameters
valueboolean- the literal
Returns
nullValue
public Object nullValue()null.Returns
allowNonFinite
public boolean allowNonFinite()NaN, Infinity and -Infinity are read, and a number such
as 1e999 is read as infinite rather than refused. JavaScript’s and
Python’s JSON writers emit these.Returns
allowControlCharacters
public boolean allowControlCharacters()