Interface OracleJsonGenerator
- All Superinterfaces:
AutoCloseable,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();
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this generator and frees any resources associated with it.voidflush()Flushes the underlying output source.<T> TReturns a JSON-P (javax.json.stream) wrapper around this value.write(boolean value) Writes the specified value as JSON true or false.write(byte[] value) Writes the specified value as a SQL/JSON binary value.write(double value) Writes the specified value as a JSON double.write(float value) Writes the specified value as a JSON float.write(int value) Writes the specified value as a JSON number.write(long value) Writes the specified value as a JSON number.Writes the specified string value as a JSON string.A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(String name, BigDecimal value) A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(String name, BigInteger value) A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(String name, LocalDateTime value) A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(String name, OffsetDateTime value) A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(String key, OracleJsonValue value) A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).write(BigDecimal value) Writes the specified value as a JSON number.write(BigInteger value) Writes the specified value as a JSON number.Writes the specified value as a SQL/JSON day/second interval.write(LocalDateTime value) Writes the specified value as a SQL/JSON timestamp.write(OffsetDateTime value) Writes the specified value as a SQL/JSON timestamp with timezone.Writes the specified value as a SQL/JSON year/month interval.write(OracleJsonValue value) Writes the specified value.writeEnd()Writes the end of the current object or array.writeId(byte[] value) Writes the specified value as a SQL/JSON binary value.Writes a JSON name/value pair in the current object context.Writes JSON null.A convenience method that is equivalent to callingwriteKey(name)and thenwriteNull().writeParser(Object parser) Writes the events from the specified parser to this generator.Begins a new JSON array.writeStartArray(String name) A convenience method that is equivalent to callingwriteKey(name)and thenwriteStartArray().Begins a new JSON object.writeStartObject(String name) A convenience method that is equivalent to callingwriteKey(name)and thenwriteStartObject().
-
Method Details
-
writeStartObject
OracleJsonGenerator writeStartObject()Begins a new JSON object. It starts a new child object context within which JSON name/value pairs can be written to the object.- Returns:
- this generator
- Throws:
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 written
-
writeStartObject
A convenience method that is equivalent to callingwriteKey(name)and thenwriteStartObject().- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
writeStartArray
OracleJsonGenerator writeStartArray()Begins a new JSON array. It starts a new child array context within which JSON values can be written to the array.- Returns:
- this generator
- Throws:
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 written
-
writeStartArray
A convenience method that is equivalent to callingwriteKey(name)and thenwriteStartArray().- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
writeKey
Writes a JSON name/value pair in the current object context. It starts a field context in which a value may be written.- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an field, array, or no context.
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified string value as a JSON string.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON number.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON number.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON number.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON number.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON double.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a JSON float.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as JSON true or false.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a SQL/JSON timestamp. To write the local date time as a date rather than a timestamp, useOracleJsonFactory.createDate(LocalDateTime)andwrite(OracleJsonValue).- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
Writes the specified value as a SQL/JSON timestamp with timezone.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a SQL/JSON year/month interval.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a SQL/JSON day/second interval.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
write
Writes the specified value as a SQL/JSON binary value.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
writeId
Writes the specified value as a SQL/JSON binary value. The value will be annotated as an identifier.- Parameters:
value- the value to be written- Returns:
- this generator
- Throws:
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 written
-
write
A convenience method that is equivalent to callingwriteKey(name)and thenwrite(value).- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
writeNull
OracleJsonGenerator writeNull()Writes JSON null.- Returns:
- this generator
- Throws:
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 written
-
writeNull
A convenience method that is equivalent to callingwriteKey(name)and thenwriteNull().- Parameters:
name- the name of a JSON field- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is not called within an object context
-
writeEnd
OracleJsonGenerator writeEnd()Writes the end of the current object or array. The parent context becomes the new current context.- Returns:
- this generator
- Throws:
OracleJsonException- - if an i/o error occursOracleJsonGenerationException- - if this method is called in no context
-
writeParser
Writes the events from the specified parser to this generator. The parser can be either an instance ofjavax.json.JsonParserorOracleJsonParser. 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
- Parameters:
parser- the parser to be written- Returns:
- this generator
- Throws:
OracleJsonException- - 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 written
-
close
void close()Closes this generator and frees any resources associated with it. The underlying output source is closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
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)
-
flush
void flush()Flushes the underlying output source. This method may do nothing for some implementations.- Specified by:
flushin interfaceFlushable- Throws:
OracleJsonException- - if an i/o error occurs
-
wrap
Returns a JSON-P (javax.json.stream) wrapper around this value. For example: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.
- Parameters:
wrapper- the interface to view this object as. Must be assignable tojavax.json.stream.JsonGenerator
-