Class DelegateJsonWriter
- java.lang.Object
-
- io.avaje.jsonb.spi.DelegateJsonWriter
-
- All Implemented Interfaces:
JsonWriter
,Closeable
,Flushable
,AutoCloseable
public abstract class DelegateJsonWriter extends Object implements JsonWriter
Provides a delegating JsonWriter.
-
-
Field Summary
Fields Modifier and Type Field Description protected JsonWriter
delegate
-
Constructor Summary
Constructors Constructor Description DelegateJsonWriter(JsonWriter delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allNames(PropertyNames names)
Set the property names that will be used for all json generation.void
beginArray()
Write array begin.void
beginObject()
Write object begin.void
close()
Close the writer.void
emptyArray()
Write empty array.void
endArray()
Write array end.void
endObject()
Write object end.void
flush()
Flush the writer.void
jsonValue(Object value)
Write a value that could be any value.void
markIncomplete()
Mark the generated json as not completed due to an error.void
name(int position)
Set the next property name to write by position.void
name(String name)
Set the next property name to write.void
names(PropertyNames names)
Set the current property names.void
nullValue()
Write null value.String
path()
Return the current path.void
pretty(boolean pretty)
Set tp true to output json in pretty format.void
rawValue(String value)
Write raw JSON content.boolean
serializeEmpty()
Return true if empty collections should be serialised.void
serializeEmpty(boolean serializeEmpty)
Set to serialise empty collections or not.boolean
serializeNulls()
Return true if null values should be serialised.void
serializeNulls(boolean serializeNulls)
Set to serialise null values or not.<T> T
unwrap(Class<T> underlying)
Unwrap the underlying generator being used.void
value(boolean value)
Write a boolean value.void
value(byte[] value)
Write binary content as base64.void
value(double value)
Write a double value.void
value(int value)
Write an int value.void
value(long value)
Write a long value.void
value(Boolean value)
Write a Boolean value.void
value(Double value)
Write a Double value.void
value(Integer value)
Write an Integer value.void
value(Long value)
Write a Long value.void
value(String value)
Write a string value.void
value(BigDecimal value)
Write a BigDecimal value.void
value(BigInteger value)
Write a BigInteger value.void
writeNewLine()
Write raw content.
-
-
-
Field Detail
-
delegate
protected final JsonWriter delegate
-
-
Constructor Detail
-
DelegateJsonWriter
public DelegateJsonWriter(JsonWriter delegate)
-
-
Method Detail
-
unwrap
public <T> T unwrap(Class<T> underlying)
Description copied from interface:JsonWriter
Unwrap the underlying generator being used.We do this to get access to the underlying generator. For the case when using jackson-core we get access to Jackson JsonGenerator and can then do Jackson specific things like set custom escaping.
try (JsonWriter writer = jsonb.writer(new StringWriter())) { // get access to the underlying Jackson JsonGenerator var generator = writer.unwrap(JsonGenerator.class) // do Jackson specific things like ... generator.setCharacterEscapes(new HTMLCharacterEscapes()); jsonb.toJson(myBean, writer); }
- Specified by:
unwrap
in interfaceJsonWriter
-
serializeNulls
public final void serializeNulls(boolean serializeNulls)
Description copied from interface:JsonWriter
Set to serialise null values or not.- Specified by:
serializeNulls
in interfaceJsonWriter
-
serializeNulls
public final boolean serializeNulls()
Description copied from interface:JsonWriter
Return true if null values should be serialised.- Specified by:
serializeNulls
in interfaceJsonWriter
-
serializeEmpty
public final boolean serializeEmpty()
Description copied from interface:JsonWriter
Return true if empty collections should be serialised.- Specified by:
serializeEmpty
in interfaceJsonWriter
-
serializeEmpty
public final void serializeEmpty(boolean serializeEmpty)
Description copied from interface:JsonWriter
Set to serialise empty collections or not.- Specified by:
serializeEmpty
in interfaceJsonWriter
-
pretty
public final void pretty(boolean pretty)
Description copied from interface:JsonWriter
Set tp true to output json in pretty format.- Specified by:
pretty
in interfaceJsonWriter
-
path
public final String path()
Description copied from interface:JsonWriter
Return the current path.- Specified by:
path
in interfaceJsonWriter
-
beginArray
public final void beginArray()
Description copied from interface:JsonWriter
Write array begin.- Specified by:
beginArray
in interfaceJsonWriter
-
endArray
public final void endArray()
Description copied from interface:JsonWriter
Write array end.- Specified by:
endArray
in interfaceJsonWriter
-
emptyArray
public final void emptyArray()
Description copied from interface:JsonWriter
Write empty array.- Specified by:
emptyArray
in interfaceJsonWriter
-
beginObject
public final void beginObject()
Description copied from interface:JsonWriter
Write object begin.- Specified by:
beginObject
in interfaceJsonWriter
-
endObject
public final void endObject()
Description copied from interface:JsonWriter
Write object end.- Specified by:
endObject
in interfaceJsonWriter
-
name
public final void name(String name)
Description copied from interface:JsonWriter
Set the next property name to write.This is generally less efficient than using
JsonWriter.names(PropertyNames)
andJsonWriter.name(int)
.- Specified by:
name
in interfaceJsonWriter
-
allNames
public void allNames(PropertyNames names)
Description copied from interface:JsonWriter
Set the property names that will be used for all json generation.These names should be used for all json generation for this generator and set once rather than set per object via
JsonWriter.names(PropertyNames)
.This is used by view json generation where all the names are known at the point when the view is created (a sort of flattened nested tree).
- Specified by:
allNames
in interfaceJsonWriter
-
names
public final void names(PropertyNames names)
Description copied from interface:JsonWriter
Set the current property names.This is expected to be called per object after each call to
JsonWriter.beginObject()
.- Specified by:
names
in interfaceJsonWriter
-
name
public final void name(int position)
Description copied from interface:JsonWriter
Set the next property name to write by position. This uses the already encoded name values of PropertyNames.- Specified by:
name
in interfaceJsonWriter
-
nullValue
public final void nullValue()
Description copied from interface:JsonWriter
Write null value.- Specified by:
nullValue
in interfaceJsonWriter
-
value
public final void value(String value)
Description copied from interface:JsonWriter
Write a string value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(boolean value)
Description copied from interface:JsonWriter
Write a boolean value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(int value)
Description copied from interface:JsonWriter
Write an int value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(long value)
Description copied from interface:JsonWriter
Write a long value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(double value)
Description copied from interface:JsonWriter
Write a double value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(Boolean value)
Description copied from interface:JsonWriter
Write a Boolean value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(Integer value)
Description copied from interface:JsonWriter
Write an Integer value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(Long value)
Description copied from interface:JsonWriter
Write a Long value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(Double value)
Description copied from interface:JsonWriter
Write a Double value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(BigDecimal value)
Description copied from interface:JsonWriter
Write a BigDecimal value.- Specified by:
value
in interfaceJsonWriter
-
value
public final void value(BigInteger value)
Description copied from interface:JsonWriter
Write a BigInteger value.- Specified by:
value
in interfaceJsonWriter
-
value
public void value(byte[] value)
Description copied from interface:JsonWriter
Write binary content as base64.- Specified by:
value
in interfaceJsonWriter
-
rawValue
public void rawValue(String value)
Description copied from interface:JsonWriter
Write raw JSON content.- Specified by:
rawValue
in interfaceJsonWriter
-
jsonValue
public final void jsonValue(Object value)
Description copied from interface:JsonWriter
Write a value that could be any value.- Specified by:
jsonValue
in interfaceJsonWriter
-
writeNewLine
public final void writeNewLine()
Description copied from interface:JsonWriter
Write raw content. This is typically used to write new line characters forx-json-stream
content.- Specified by:
writeNewLine
in interfaceJsonWriter
-
flush
public final void flush()
Description copied from interface:JsonWriter
Flush the writer.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in interfaceJsonWriter
-
close
public void close()
Description copied from interface:JsonWriter
Close the writer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceJsonWriter
-
markIncomplete
public void markIncomplete()
Description copied from interface:JsonWriter
Mark the generated json as not completed due to an error.This typically means not to flush or close an underlying OutputStream which allows it to be reset to then write some error response content instead.
- Specified by:
markIncomplete
in interfaceJsonWriter
-
-