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.Closeable
Writes 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
-
<section role="region">
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description JSONWriter
append(JSONToken token)
Write aJSONToken
instance to the stream.JSONWriter
endArray()
End an array, emit the closing square bracket (]
).JSONWriter
endObject()
End an object, emit the closing brace (}
).JSONWriter
nullValue()
Emit a null property value.JSONWriter
property(java.lang.String name, java.lang.CharSequence value)
Emit a property with a textual value.JSONWriter
propertyName(java.lang.String name)
Emit the name of a propertyJSONWriter
startArray()
Start an array, emit the opening square bracket([
)JSONWriter
startObject()
Start an object, emit the opening brace ({
).JSONWriter
value(java.lang.Boolean value)
Emit a boolean value, mapping it to the unquoted values:true
orfalse
JSONWriter
value(java.lang.CharSequence value)
Emit a textual value, quoting and escaping the stringJSONWriter
value(java.lang.Number value)
Emit a numeric value.JSONWriter
value(java.lang.Readable value)
Emit a textual value, quoting and escaping the string.
-
-
<section role="region">
-
Method Detail
-
append
JSONWriter append(JSONToken token) throws JSONIOException
Write aJSONToken
instance 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:true
orfalse
- 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
-
-