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

  1. Object
  2. 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

public Object newObject()Opens an object.
public void put(Object object, String key, Object value)Adds one member to an object opened by newObject().
public Object endObject(Object object)Closes an object.
public Object newArray()Opens an array.
public void add(Object array, Object value)Appends one element to an array opened by newArray().
public Object endArray(Object array)Closes an array.
public Object string(String value)A string value.
public Object integer(long value)An integer that fits a long.
public Object bigInteger(String digits) throws IOExceptionAn integer too large for a long.
public Object decimal(double value)A number with a fraction or an exponent, or a non-finite one when allowNonFinite() is on.
public Object bool(boolean value)true or false.
public Object nullValue()null.
public boolean allowNonFinite()Whether NaN, Infinity and -Infinity are read, and a number such as 1e999 is read as infinite rather than refused.
public boolean allowControlCharacters()Whether a control character below U+0020 may appear unescaped inside a string.

Inherited methods

Constructor details

JSONValueFactory

public JSONValueFactory()

Method details

newObject

public Object newObject()
Opens an object.

Returns

the new, empty container, handed back to put(Object, String, Object) and endObject(Object)

put

public void put(Object object, String key, Object value)
Adds one member to an object opened by newObject(). A key may repeat; the reader passes every occurrence in order.

Parameters

object Object
the container
key String
the member name
value Object
the member value

endObject

public Object endObject(Object object)
Closes an object.

Parameters

object Object
the container

Returns

the value the parent receives, normally the container itself

newArray

public Object newArray()
Opens an array.

Returns

the new, empty container

add

public void add(Object array, Object value)
Appends one element to an array opened by newArray().

Parameters

array Object
the container
value Object
the element

endArray

public Object endArray(Object array)
Closes an array.

Parameters

array Object
the container

Returns

the value the parent receives, normally the container itself

string

public Object string(String value)
A string value. Member names are not passed here.

Parameters

value String
the decoded string

Returns

the value to store

integer

public Object integer(long value)
An integer that fits a long.

Parameters

value long
the integer

Returns

the value to store

bigInteger

public Object bigInteger(String digits) throws IOException
An integer too large for a long.

Parameters

digits String
the integer as written, with its sign

Returns

the value to store

Throws

IOException
to refuse it, which this class does

decimal

public Object decimal(double value)
A number with a fraction or an exponent, or a non-finite one when allowNonFinite() is on.

Parameters

value double
the number

Returns

the value to store

bool

public Object bool(boolean value)
true or false.

Parameters

value boolean
the literal

Returns

the value to store

nullValue

public Object nullValue()
null.

Returns

the value to store

allowNonFinite

public boolean allowNonFinite()
Whether 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

false, as RFC 8259 requires

allowControlCharacters

public boolean allowControlCharacters()
Whether a control character below U+0020 may appear unescaped inside a string.

Returns

false, as RFC 8259 requires