public final class JSONCollector extends java.lang.Object implements StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
JSONObject
, JSONArray
, and
JSONObject.NULL
instances.
This collector holds no state, so a singleton is provided.
Modifier and Type | Field and Description |
---|---|
static JSONCollector |
INSTANCE
The singleton instance of this collector.
|
Modifier and Type | Method and Description |
---|---|
void |
addNull(JSONArray array)
Adds a
JSONObject.NULL value to the given JSONArray . |
void |
addNull(JSONObject object,
java.lang.String key)
Adds a
JSONObject.NULL value an an entry to the given
JSONObject . |
void |
addValue(JSONArray array,
java.lang.Object value)
Adds the given value to the given JSON array accumulator.
|
void |
addValue(JSONObject object,
java.lang.String key,
java.lang.Object value)
Adds the given entry to the given JSON object.
|
JSONArray |
createArrayAccumulator()
Create a new
JSONArray into which JSON array entries are added. |
JSONObject |
createObjectAccumulator()
Create a new
JSONObject into which JSON object entries are added. |
JSONArray |
finishArray(JSONArray accumulator)
Finish the given JSON array accumulator, returning the array result.
|
JSONObject |
finishObject(JSONObject accumulator)
Finish the given JSON object accumulator, returning the object result.
|
java.lang.Object |
nullValue()
Provide a null value for circumstances where JSON null is the complete
result of a JSON parse.
|
public static final JSONCollector INSTANCE
public JSONObject createObjectAccumulator()
JSONObject
into which JSON object entries are added.createObjectAccumulator
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
JSONObject
instancepublic void addValue(JSONObject object, java.lang.String key, java.lang.Object value) throws JSONException
StructureCollector
addValue
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
object
- the JSON object accumulator to which the entry will be addedkey
- the key of the entryvalue
- the value of the entryJSONException
- may be thrown if a duplicate key is encounteredpublic void addNull(JSONObject object, java.lang.String key) throws JSONException
JSONObject.NULL
value an an entry to the given
JSONObject
.addNull
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
object
- the target to which the entry will be addedkey
- the key of the entryJSONException
- a duplicate key is encounteredpublic JSONObject finishObject(JSONObject accumulator)
StructureCollector
finishObject
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
accumulator
- the JSON object accumulator to be finishedpublic JSONArray createArrayAccumulator()
JSONArray
into which JSON array entries are added.createArrayAccumulator
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
JSONArray
instancepublic void addValue(JSONArray array, java.lang.Object value) throws JSONException
StructureCollector
addValue
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
array
- the JSON array accumulator to which the value will be addedvalue
- the value to be addedJSONException
public void addNull(JSONArray array) throws JSONException
JSONObject.NULL
value to the given JSONArray
.addNull
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
array
- the target to which the null value will be addedJSONException
public JSONArray finishArray(JSONArray accumulator)
StructureCollector
finishArray
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
accumulator
- the JSON array accumulator to be finishedpublic java.lang.Object nullValue()
nullValue
in interface StructureCollector<JSONObject,JSONArray,JSONObject,JSONArray>
JSONObject.NULL
value