Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends one element to an array opened bynewArray().booleanWhether a control character below U+0020 may appear unescaped inside a string.booleanWhetherNaN,Infinityand-Infinityare read, and a number such as1e999is read as infinite rather than refused.bigInteger(String digits) An integer too large for along.bool(boolean value) trueorfalse.decimal(double value) A number with a fraction or an exponent, or a non-finite one whenallowNonFinite()is on.Closes an array.Closes an object.integer(long value) An integer that fits along.newArray()Opens an array.Opens an object.null.voidAdds one member to an object opened bynewObject().A string value.
-
Constructor Details
-
JSONValueFactory
public JSONValueFactory()
-
-
Method Details
-
newObject
Opens an object.
Returns
the new, empty container, handed back to
put(Object, String, Object)andendObject(Object) -
put
Adds one member to an object opened by
newObject(). A key may repeat; the reader passes every occurrence in order.Parameters
-
object: the container -
key: the member name -
value: the member value
-
-
endObject
-
newArray
Opens an array.
Returns
the new, empty container
-
add
Appends one element to an array opened by
newArray().Parameters
-
array: the container -
value: the element
-
-
endArray
-
string
-
integer
An integer that fits a
long.Parameters
value: the integer
Returns
the value to store
-
bigInteger
An integer too large for a
long.Parameters
digits: the integer as written, with its sign
Returns
the value to store
Throws
IOException: to refuse it, which this class does
- Throws:
IOException
-
decimal
A number with a fraction or an exponent, or a non-finite one when
allowNonFinite()is on.Parameters
value: the number
Returns
the value to store
-
bool
trueorfalse.Parameters
value: the literal
Returns
the value to store
-
nullValue
null.Returns
the value to store
-
allowNonFinite
public boolean allowNonFinite()Whether
NaN,Infinityand-Infinityare read, and a number such as1e999is 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
-