public interface OracleJsonGenerator extends Closeable, Flushable
Writes a JSON type value to an output source. A JSON generator starts out in no context. As methods on the generator are called, the context changes. The current context determines which methods may be called next on the generator, as defined below.
The generator can be used to create a value as either a sequence of events
or by writing full JSON values (instances of OracleJsonValue
). For
example, the following code creates an instance of OracleJsonObject
and then uses OracleJsonGenerator
to write it as binary JSON.
OracleJsonFactory factory = new OracleJsonFactory();
OracleJsonObject obj = factory.createObject();
obj.put("hello", "world");
ByteArrayOutputStream out = new ByteArrayOutputStream();
OracleJsonGenerator generator = factory.createJsonBinaryGenerator(out);
generator.write(obj);
generator.close();
byte[] binaryJson = out.toByteArray();
The next example generates the same binary JSON value from a sequence of events:
ByteArrayOutputStream out = new ByteArrayOutputStream();
OracleJsonGenerator generator = factory.createJsonBinaryGenerator(out);
generator.writeStartObject();
generator.writeKey("hello");
generator.write("world");
generator.writeEnd();
generator.close();
byte[] binaryJson = out.toByteArray();
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this generator and frees any resources associated with it.
|
void |
flush()
Flushes the underlying output source.
|
<T> T |
wrap(Class<T> wrapper)
Returns a JSON-P (javax.json.stream) wrapper around this value.
|
OracleJsonGenerator |
write(BigDecimal value)
Writes the specified value as a JSON number.
|
OracleJsonGenerator |
write(BigInteger value)
Writes the specified value as a JSON number.
|
OracleJsonGenerator |
write(boolean value)
Writes the specified value as JSON true or false.
|
OracleJsonGenerator |
write(byte[] value)
Writes the specified value as a SQL/JSON binary value.
|
OracleJsonGenerator |
write(double value)
Writes the specified value as a JSON double.
|
OracleJsonGenerator |
write(java.time.Duration value)
Writes the specified value as a SQL/JSON day/second interval.
|
OracleJsonGenerator |
write(float value)
Writes the specified value as a JSON float.
|
OracleJsonGenerator |
write(int value)
Writes the specified value as a JSON number.
|
OracleJsonGenerator |
write(java.time.LocalDateTime value)
Writes the specified value as a SQL/JSON timestamp.
|
OracleJsonGenerator |
write(long value)
Writes the specified value as a JSON number.
|
OracleJsonGenerator |
write(java.time.OffsetDateTime value)
Writes the specified value as a SQL/JSON timestamp with timezone.
|
OracleJsonGenerator |
write(OracleJsonValue value)
Writes the specified value.
|
OracleJsonGenerator |
write(java.time.Period value)
Writes the specified value as a SQL/JSON year/month interval.
|
OracleJsonGenerator |
write(String value)
Writes the specified string value as a JSON string.
|
OracleJsonGenerator |
write(String name,
BigDecimal value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
BigInteger value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
boolean value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
byte[] value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
double value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
java.time.Duration value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
float value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
int value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
java.time.LocalDateTime value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
long value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
java.time.OffsetDateTime value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String key,
OracleJsonValue value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
java.time.Period value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
write(String name,
String value)
A convenience method that is equivalent to calling
writeKey(name)
and then write(value) . |
OracleJsonGenerator |
writeEnd()
Writes the end of the current object or array.
|
OracleJsonGenerator |
writeId(byte[] value)
Writes the specified value as a SQL/JSON binary value.
|
OracleJsonGenerator |
writeKey(String name)
Writes a JSON name/value pair in the current object context.
|
OracleJsonGenerator |
writeNull()
Writes JSON null.
|
OracleJsonGenerator |
writeNull(String name)
A convenience method that is equivalent to calling
writeKey(name)
and then writeNull() . |
OracleJsonGenerator |
writeParser(Object parser)
Writes the events from the specified parser to this generator.
|
OracleJsonGenerator |
writeStartArray()
Begins a new JSON array.
|
OracleJsonGenerator |
writeStartArray(String name)
A convenience method that is equivalent to calling
writeKey(name)
and then writeStartArray() . |
OracleJsonGenerator |
writeStartObject()
Begins a new JSON object.
|
OracleJsonGenerator |
writeStartObject(String name)
A convenience method that is equivalent to calling
writeKey(name)
and then writeStartObject() . |
OracleJsonGenerator writeStartObject()
OracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonGenerator writeStartObject(String name)
writeKey(name)
and then writeStartObject()
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator writeStartArray()
OracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonGenerator writeStartArray(String name)
writeKey(name)
and then writeStartArray()
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator writeKey(String name)
name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(OracleJsonValue value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an field, array, or no context.OracleJsonGenerator write(String key, OracleJsonValue value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(String value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonGenerator write(String name, String value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(BigDecimal value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonDecimal}
,
OracleJsonParser.Event#VALUE_DECIMAL}
OracleJsonGenerator write(String name, BigDecimal value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(BigInteger value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonDecimal}
,
OracleJsonParser.Event#VALUE_DECIMAL}
OracleJsonGenerator write(String name, BigInteger value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(int value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonDecimal}
,
OracleJsonParser.Event#VALUE_DECIMAL}
OracleJsonGenerator write(String name, int value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(long value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonDecimal}
,
OracleJsonParser.Event#VALUE_DECIMAL}
OracleJsonGenerator write(String name, long value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(double value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonDouble}
,
OracleJsonParser.Event#VALUE_DOUBLE}
OracleJsonGenerator write(String name, double value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(float value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonFloat}
,
OracleJsonParser.Event#VALUE_FLOAT}
OracleJsonGenerator write(String name, float value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(boolean value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonValue.OracleJsonType#TRUE}
,
OracleJsonValue.OracleJsonType#FALSE}
,
OracleJsonParser.Event#VALUE_TRUE}
,
OracleJsonParser.Event#VALUE_FALSE}
OracleJsonGenerator write(String name, boolean value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(java.time.LocalDateTime value)
OracleJsonFactory.createDate(LocalDateTime)
and
write(OracleJsonValue)
.value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonTimestamp}
,
OracleJsonParser.Event#VALUE_TIMESTAMP}
OracleJsonGenerator write(java.time.OffsetDateTime value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonTimestampTZ}
,
OracleJsonParser.Event#VALUE_TIMESTAMPTZ}
OracleJsonGenerator write(String name, java.time.LocalDateTime value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(String name, java.time.OffsetDateTime value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(java.time.Period value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonIntervalYM}
,
OracleJsonParser.Event#VALUE_INTERVALYM}
OracleJsonGenerator write(String name, java.time.Period value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(java.time.Duration value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonIntervalDS}
,
OracleJsonParser.Event#VALUE_INTERVALDS}
OracleJsonGenerator write(String name, java.time.Duration value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator write(byte[] value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonBinary}
,
OracleJsonParser.Event#VALUE_BINARY}
OracleJsonGenerator writeId(byte[] value)
value
- the value to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonBinary}
,
OracleJsonParser.Event#VALUE_BINARY}
,
OracleJsonBinary#isId()}
OracleJsonGenerator write(String name, byte[] value)
writeKey(name)
and then write(value)
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator writeNull()
OracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or it is called in no context when a value has already been writtenOracleJsonValue.OracleJsonType#NULL}
,
OracleJsonParser.Event#VALUE_NULL}
OracleJsonGenerator writeNull(String name)
writeKey(name)
and then writeNull()
.name
- the name of a JSON fieldOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is not called within
an object contextOracleJsonGenerator writeEnd()
OracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this method is called in no contextOracleJsonGenerator writeParser(Object parser)
javax.json.JsonParser
or OracleJsonParser
. The purpose of this method is to allow events from one
type of source to be piped into another type of source. For example,
this method can be used to convert JSON text to binary JSON by passing in a
JSON text parser to a binary generator.
The method writes the full value for the current event of the specified parser. The parser will not be closed by this method
parser
- the parser to be writtenOracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if this is called within an object
context or if it no context and a value has already been writtenvoid close()
close
in interface AutoCloseable
close
in interface Closeable
OracleJsonException
- - if an i/o error occursOracleJsonGenerationException
- - if an incomplete JSON value is
generated (no events have been written or there is still a context that
needs to be closed)void flush()
flush
in interface Flushable
OracleJsonException
- - if an i/o error occurs<T> T wrap(Class<T> wrapper)
import javax.json.stream.JsonGenerator;
...
OracleJsonGenerator oraGenerator = ...;
JsonGenerator generator = oraGenerator.wrap(JsonGenerator.class);
The returned object is a logical view of this generator. Any changes to the state of this generator are observed by the returned wrapper object.
wrapper
- the interface to view this object as. Must be assignable to
javax.json.stream.JsonGenerator