Package oracle.dbtools.plugin.api.json
Interface JSONWriter
- All Superinterfaces:
AutoCloseable,Closeable,Flushable
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
-
Method Summary
Modifier and TypeMethodDescriptionWrite aJSONTokeninstance to the stream.endArray()End an array, emit the closing square bracket (]).End an object, emit the closing brace (}).default JSONWritererrorValue(String error, String errorpropertyName, String errorMessage, String errorAction) Outputs an inline error object value in place of an inlined JSON value where it is either malformed or cannot be generated.graftChildren(boolean setting) Grafts the properties of the child objects onto the current object inside of creating a new level.Emit a null property value.property(String name, CharSequence value) Emit a property with a textual value.propertyName(String name) Emit the name of a propertyStart an array, emit the opening square bracket([)Start an object, emit the opening brace ({).Emit a boolean value, mapping it to the unquoted values:trueorfalsevalue(CharSequence value) Emit a textual value, quoting and escaping the stringEmit a numeric value.Emit a textual value, quoting and escaping the string.
-
Method Details
-
append
Write aJSONTokeninstance to the stream.- Parameters:
token- The token to write- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
endObject
End an object, emit the closing brace (}).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
endArray
End an array, emit the closing square bracket (]).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
propertyName
Emit the name of a property- Parameters:
name- The name of the property- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
property
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
Start an object, emit the opening brace ({).- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
startArray
Start an array, emit the opening square bracket([)- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
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
Emit a textual value, quoting and escaping the string- Parameters:
value- textual value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
Emit a numeric value. Note that the special Double values: are quoted, because the JSON syntax does not define any equivalent values.- Parameters:
value- Numeric value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
value
Emit a textual value, quoting and escaping the string.- Parameters:
value- textual value- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
nullValue
Emit a null property value.- Returns:
- self
- Throws:
JSONIOException- if an IO error occurs
-
errorValue
default JSONWriter errorValue(String error, String errorpropertyName, String errorMessage, String errorAction) throws JSONIOException Outputs an inline error object value in place of an inlined JSON value where it is either malformed or cannot be generated.- Parameters:
error- title or context of errorerrorpropertyName- The name of the errored propertyerrorMessage- error messageerrorAction- error action- Returns:
- self
- Throws:
JSONIOException
-
graftChildren
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
-