public interface JSONAppendable
JSONAppendable
interface provides a appendJSON()
method so that a class can change the behavior of
JSONObject.toString()
, JSONArray.toString()
,
and JSONWriter.value(Object)
. The
appendJSON()
method will be used instead of the default behavior
of using the Object's toString()
method and quoting the result.
The classes JSONWriter
and BufferedAppendable
may be used to help generate a valid JSON value.
Prefer this interface over the JSONString
interface whenever a
large value needs to be written. This can avoid excessive buffering or
memory usage.
JSONString
Modifier and Type | Method and Description |
---|---|
void |
appendJSON(java.lang.Appendable appender)
The
appendJSON() method allows a class to produce its own JSON
serialization. |
void appendJSON(java.lang.Appendable appender) throws java.io.IOException, JSONException
appendJSON()
method allows a class to produce its own JSON
serialization. If called, a valid JSON value must be written, even if
it is an empty object {}
, empty array []
, or a null
value null
.
If a runtime exception is thrown, this will be caught and propagated
as a JSONException
.
appender
- an Appendable
to which a strictly syntactically
correct JSON value must be writtenjava.io.IOException
- there was an I/O error appending the JSON valueJSONException
- there was a problem creating the JSON value