Package oracle.dbtools.plugin.api.json
Interface JSONWriter
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable,java.io.Flushable
public interface JSONWriter extends java.io.Flushable, java.io.CloseableWrites JSON content to a character stream.Examples
Writing a basic object
final JSONStreams json = ...; // acquire the JSONStreams service final Appendable output = ...; // create a stream to write to ... final JSONWriter writer = json.jsonWriter(output); writer.startObject().property("foo","bar").endObject(); //writes: {"foo":"bar"}Writing a nested object
final JSONStreams json = ...; // acquire the JSONStreams service final Appendable output = ...; // create a stream to write to ... final JSONWriter writer = json.jsonWriter(output); writer.startObject() .propertyName("nested") .startObject() .property("foo","bar") .endObject() .endObject(); //writes: {"nested":{"foo":"bar"}}Writing an array value
final JSONStreams json = ...; // acquire the JSONStreams service final Appendable output = ...; // create a stream to write to ... final JSONWriter writer = json.jsonWriter(output); writer.startObject() .propertyName("items") .startArray() .value("first") .value("second") .nullValue() .endObject() .endObject(); //writes: {"items":["first","second",null]}- Author:
- cdivilly
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JSONWriterappend(JSONToken token)Write aJSONTokeninstance to the stream.JSONWriterendArray()End an array, emit the closing square bracket (]).JSONWriterendObject()End an object, emit the closing brace (}).JSONWritergraftChildren(boolean setting)Grafts the properties of the child objects onto the current object inside of creating a new level.JSONWriternullValue()Emit a null property value.JSONWriterproperty(java.lang.String name, java.lang.CharSequence value)Emit a property with a textual value.JSONWriterpropertyName(java.lang.String name)Emit the name of a propertyJSONWriterstartArray()Start an array, emit the opening square bracket([)JSONWriterstartObject()Start an object, emit the opening brace ({).JSONWritervalue(java.lang.Boolean value)Emit a boolean value, mapping it to the unquoted values:trueorfalseJSONWritervalue(java.lang.CharSequence value)Emit a textual value, quoting and escaping the stringJSONWritervalue(java.lang.Number value)Emit a numeric value.JSONWritervalue(java.lang.Readable value)Emit a textual value, quoting and escaping the string.
-
-
-
Method Detail
-
append
JSONWriter append(JSONToken token) throws JSONIOException
Write aJSONTokeninstance to the stream.- Parameters:
token- The token to write- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
endObject
JSONWriter endObject() throws JSONIOException
End an object, emit the closing brace (}).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
endArray
JSONWriter endArray() throws JSONIOException
End an array, emit the closing square bracket (]).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
propertyName
JSONWriter propertyName(java.lang.String name) throws JSONIOException
Emit the name of a property- Parameters:
name- The name of the property- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
property
JSONWriter property(java.lang.String name, java.lang.CharSequence value) throws JSONIOException
Emit a property with a textual value.- Parameters:
name- Name of the propertyvalue- The value of the property- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
startObject
JSONWriter startObject() throws JSONIOException
Start an object, emit the opening brace ({).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
startArray
JSONWriter startArray() throws JSONIOException
Start an array, emit the opening square bracket([)- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
JSONWriter value(java.lang.Boolean value) throws JSONIOException
Emit a boolean value, mapping it to the unquoted values:trueorfalse- Parameters:
value- boolean value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
JSONWriter value(java.lang.CharSequence value) throws JSONIOException
Emit a textual value, quoting and escaping the string- Parameters:
value- textual value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
JSONWriter value(java.lang.Number value) throws JSONIOException
Emit a numeric value. Note that the special Double values:-
Double.NaN -
Double.POSITIVE_INFINITY -
Double.NEGATIVE_INFINITY
- Parameters:
value- Numeric value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
-
value
JSONWriter value(java.lang.Readable value) throws JSONIOException
Emit a textual value, quoting and escaping the string.- Parameters:
value- textual value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
nullValue
JSONWriter nullValue() throws JSONIOException
Emit a null property value.- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
graftChildren
JSONWriter graftChildren(boolean setting)
Grafts the properties of the child objects onto the current object inside of creating a new level. Used for Duality View to suppress the "data" level- Parameters:
setting- new level creation skipped when true- Returns:
- self
-
-