public final class JSONObjectBuilder
extends java.lang.Object
JSONStreamReader
.
This uses less stack space than parsing via JSONTokener
,
since only one stack frame is allocated per nested object or array.
A simple example of how to use this class:
JSONObject jsonObject = JSONObjectBuilder.buildJSONObject(JSON_TEXT);
Modifier and Type | Method and Description |
---|---|
static JSONArray |
buildArraySubTree(JSONStreamReader reader)
If the given
JSONStreamReader 's ParseState was JSONStreamReader.ParseState.ARRAY ,
return the entire subtree as a JSONArray value. |
static <AR> AR |
buildArraySubTree(JSONStreamReader reader,
StructureCollector<?,?,?,AR> collector)
If the given
JSONStreamReader 's ParseState was JSONStreamReader.ParseState.ARRAY ,
return the entire subtree as an array type, as specified by the given
collector. |
static JSONArray |
buildJSONArray(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a
JSONArray from a InputStream and a supplied
Charset . |
static <AR> AR |
buildJSONArray(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a InputStream and a supplied
Charset . |
static JSONArray |
buildJSONArray(JSONStreamReader reader)
Build a
JSONArray from a JSONStreamReader . |
static <AR> AR |
buildJSONArray(JSONStreamReader reader,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a JSONStreamReader . |
static JSONArray |
buildJSONArray(java.io.Reader reader)
Build a
JSONArray from a Reader . |
static <AR> AR |
buildJSONArray(java.io.Reader reader,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a Reader . |
static JSONArray |
buildJSONArray(java.lang.String s)
Build a
JSONArray from a String . |
static <AR> AR |
buildJSONArray(java.lang.String s,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a String . |
static JSONObject |
buildJSONObject(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a
JSONObject from a InputStream and a supplied
Charset . |
static <OR> OR |
buildJSONObject(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a InputStream and a supplied
Charset . |
static JSONObject |
buildJSONObject(JSONStreamReader reader)
Build a
JSONObject from a JSONStreamReader . |
static <OR> OR |
buildJSONObject(JSONStreamReader reader,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a JSONStreamReader . |
static JSONObject |
buildJSONObject(java.io.Reader reader)
Build a
JSONObject from a Reader . |
static <OR> OR |
buildJSONObject(java.io.Reader reader,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a Reader . |
static JSONObject |
buildJSONObject(java.lang.String s)
Build a
JSONObject from a String . |
static <OR> OR |
buildJSONObject(java.lang.String s,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a String . |
static java.lang.Object |
buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a JSON value from a
InputStream and supplied
Charset . |
static java.lang.Object |
buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
InputStream and supplied
Charset . |
static java.lang.Object |
buildJSONValue(JSONStreamReader reader)
Build a JSON value from a
JSONStreamReader . |
static java.lang.Object |
buildJSONValue(JSONStreamReader reader,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
JSONStreamReader . |
static java.lang.Object |
buildJSONValue(java.io.Reader reader)
Build a JSON value from a
Reader . |
static java.lang.Object |
buildJSONValue(java.io.Reader reader,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
Reader . |
static java.lang.Object |
buildJSONValue(java.lang.String s)
Build a JSON value from a
String . |
static java.lang.Object |
buildJSONValue(java.lang.String s,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
String . |
static JSONObject |
buildObjectSubTree(JSONStreamReader reader)
If the given
JSONStreamReader 's ParseState was JSONStreamReader.ParseState.OBJECT ,
return the entire subtree as a JSONObject value. |
static <OR> OR |
buildObjectSubTree(JSONStreamReader reader,
StructureCollector<?,?,OR,?> collector)
If the given
JSONStreamReader 's ParseState was JSONStreamReader.ParseState.OBJECT ,
return the entire subtree as an object type, as specified by the given
collector. |
public static java.lang.Object buildJSONValue(java.io.Reader reader) throws JSONException
Reader
. The value may be one of:
JSONObject.NULL
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
JSONObject
JSONArray
reader
- A reader.JSONException
public static java.lang.Object buildJSONValue(java.io.Reader reader, StructureCollector<?,?,?,?> collector) throws JSONException
Reader
. The value may be one of:
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
reader
- A reader.collector
- A collector object for creating structuresJSONException
public static java.lang.Object buildJSONValue(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws JSONException
InputStream
and supplied
Charset
. The value may be one of:
JSONObject.NULL
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
JSONObject
JSONArray
inputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamJSONException
public static java.lang.Object buildJSONValue(java.io.InputStream inputStream, java.nio.charset.Charset charset, StructureCollector<?,?,?,?> collector) throws JSONException
InputStream
and supplied
Charset
. The value may be one of:
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
inputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamcollector
- A collector object for creating structuresJSONException
public static java.lang.Object buildJSONValue(java.lang.String s) throws JSONException
String
. The value may be one of:
JSONObject.NULL
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
JSONObject
JSONArray
s
- A source string.JSONException
public static java.lang.Object buildJSONValue(java.lang.String s, StructureCollector<?,?,?,?> collector) throws JSONException
String
. The value may be one of:
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
s
- A source string.collector
- A collector object for creating structuresJSONException
public static java.lang.Object buildJSONValue(JSONStreamReader reader) throws JSONException
JSONStreamReader
. The value may be one
of:
JSONObject.NULL
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
JSONObject
JSONArray
The reader must be at the beginning of the document.
reader
- A source stream reader.JSONException
public static java.lang.Object buildJSONValue(JSONStreamReader reader, StructureCollector<?,?,?,?> collector) throws JSONException
JSONStreamReader
. The value may be one
of:
Boolean.TRUE
or Boolean.FALSE
Double
, Long
, Integer
,
BigDecimal
, or BigInteger
String
The reader must be at the beginning of the document.
reader
- A source stream reader.collector
- A collector object for creating structuresJSONException
public static JSONObject buildJSONObject(java.io.Reader reader) throws JSONException
JSONObject
from a Reader
.reader
- A reader.JSONException
public static <OR> OR buildJSONObject(java.io.Reader reader, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONObject
from a Reader
.OR
- The resulting JSON object typereader
- A reader.collector
- A collector object for creating structuresJSONException
public static JSONObject buildJSONObject(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws JSONException
JSONObject
from a InputStream
and a supplied
Charset
.inputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamJSONException
public static <OR> OR buildJSONObject(java.io.InputStream inputStream, java.nio.charset.Charset charset, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONObject
from a InputStream
and a supplied
Charset
.OR
- The resulting JSON object typeinputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamcollector
- A collector object for creating structuresJSONException
public static JSONObject buildJSONObject(java.lang.String s) throws JSONException
JSONObject
from a String
.s
- A source string.JSONException
public static <OR> OR buildJSONObject(java.lang.String s, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONObject
from a String
.OR
- The resulting JSON object types
- A source string.collector
- A collector object for creating structuresJSONException
public static JSONObject buildJSONObject(JSONStreamReader reader) throws JSONException
JSONObject
from a JSONStreamReader
. The reader must be
at the beginning of the document.reader
- A source stream reader.JSONException
public static <OR> OR buildJSONObject(JSONStreamReader reader, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONObject
from a JSONStreamReader
. The reader must be
at the beginning of the document.OR
- The resulting JSON object typereader
- A source stream reader.collector
- A collector object for creating structuresJSONException
public static <AR> AR buildJSONArray(java.io.Reader reader, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONArray
from a Reader
.AR
- The resulting JSON array typereader
- A reader.collector
- A collector object for creating structuresJSONException
public static JSONArray buildJSONArray(java.io.Reader reader) throws JSONException
JSONArray
from a Reader
.reader
- A reader.JSONException
public static JSONArray buildJSONArray(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws JSONException
JSONArray
from a InputStream
and a supplied
Charset
.inputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamJSONException
public static <AR> AR buildJSONArray(java.io.InputStream inputStream, java.nio.charset.Charset charset, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONArray
from a InputStream
and a supplied
Charset
.AR
- The resulting JSON array typeinputStream
- the input stream containing the JSON datacharset
- the character set with which to interpret the
input streamcollector
- A collector object for creating structuresJSONException
public static JSONArray buildJSONArray(java.lang.String s) throws JSONException
JSONArray
from a String
.s
- A source string.JSONException
public static <AR> AR buildJSONArray(java.lang.String s, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONArray
from a String
.AR
- The resulting JSON array types
- A source string.collector
- A collector object for creating structuresJSONException
public static JSONArray buildJSONArray(JSONStreamReader reader) throws JSONException
JSONArray
from a JSONStreamReader
. The reader must be
at the beginning of the document.reader
- A source stream.JSONException
public static <AR> AR buildJSONArray(JSONStreamReader reader, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONArray
from a JSONStreamReader
. The reader must be
at the beginning of the document.AR
- The resulting JSON array typereader
- A source stream.collector
- A collector object for creating structuresJSONException
public static JSONObject buildObjectSubTree(JSONStreamReader reader) throws JSONException
JSONStreamReader
's ParseState
was JSONStreamReader.ParseState.OBJECT
,
return the entire subtree as a JSONObject
value. This method
advances the parser onto the JSONStreamReader.ParseState.END_OBJECT
state.
If the JSON stream is not parseable as an object, a JSONException
will be thrown.
reader
- A source stream reader.JSONObject
representing the subtree starting at the current
OBJECT stateJSONException
public static <OR> OR buildObjectSubTree(JSONStreamReader reader, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONStreamReader
's ParseState
was JSONStreamReader.ParseState.OBJECT
,
return the entire subtree as an object type, as specified by the given
collector. This method advances the parser onto the
JSONStreamReader.ParseState.END_OBJECT
state.
If the JSON stream is not parseable as an object, a JSONException
will be thrown.
OR
- The resulting JSON object typereader
- A source stream reader.collector
- A collector object for creating structuresJSONException
public static JSONArray buildArraySubTree(JSONStreamReader reader) throws JSONException
JSONStreamReader
's ParseState
was JSONStreamReader.ParseState.ARRAY
,
return the entire subtree as a JSONArray
value. This method
advances the parser onto the JSONStreamReader.ParseState.END_ARRAY
state.
If the JSON stream is not parseable as an array, a JSONException
will be thrown.
reader
- A source stream reader.JSONArray
representing the subtree starting at the current
ARRAY stateJSONException
public static <AR> AR buildArraySubTree(JSONStreamReader reader, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONStreamReader
's ParseState
was JSONStreamReader.ParseState.ARRAY
,
return the entire subtree as an array type, as specified by the given
collector. This method advances the parser onto the
JSONStreamReader.ParseState.END_ARRAY
state.
If the JSON stream is not parseable as an array, a JSONException
will be thrown.
AR
- The resulting JSON array typereader
- A source stream reader.collector
- A collector object for creating structuresJSONException