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 final JsonWriter
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Set the property names that will be used for all json generation.
    final void
    Write array begin.
    final void
    Write object begin.
    final void
    Write object being and use the already encoded property names.
    void
    Close the writer.
    final void
    Write empty array.
    final void
    Write array end.
    final void
    Write object end.
    final void
    Flush the writer.
    final void
    Write a value that could be any value.
    void
    Mark the generated json as not completed due to an error.
    final void
    name(int position)
    Set the next property name to write by position.
    final void
    name(String name)
    Set the next property name to write.
    final void
    Write null value.
    final String
    Return the current path.
    final void
    pretty(boolean pretty)
    Set tp true to output json in pretty format.
    void
    Write raw JSON content.
    final boolean
    Return true if empty collections should be serialised.
    final void
    serializeEmpty(boolean serializeEmpty)
    Set to serialise empty collections or not.
    final boolean
    Return true if null values should be serialised.
    final void
    serializeNulls(boolean serializeNulls)
    Set to serialise null values or not.
    <T> T
    unwrap(Class<T> underlying)
    Unwrap the underlying generator being used.
    final void
    value(boolean value)
    Write a boolean value.
    void
    value(byte[] value)
    Write binary content as base64.
    final void
    value(double value)
    Write a double value.
    final void
    value(int value)
    Write an int value.
    final void
    value(long value)
    Write a long value.
    final void
    value(Boolean value)
    Write a Boolean value.
    final void
    value(Double value)
    Write a Double value.
    final void
    value(Integer value)
    Write an Integer value.
    final void
    value(Long value)
    Write a Long value.
    final void
    value(String value)
    Write a string value.
    final void
    Write a BigDecimal value.
    final void
    Write a BigInteger value.
    final void
    Write new line characters typically for x-json-stream content.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • DelegateJsonWriter

      public DelegateJsonWriter(JsonWriter delegate)
  • Method Details

    • 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 interface JsonWriter
    • serializeNulls

      public final void serializeNulls(boolean serializeNulls)
      Description copied from interface: JsonWriter
      Set to serialise null values or not.
      Specified by:
      serializeNulls in interface JsonWriter
    • serializeNulls

      public final boolean serializeNulls()
      Description copied from interface: JsonWriter
      Return true if null values should be serialised.
      Specified by:
      serializeNulls in interface JsonWriter
    • serializeEmpty

      public final boolean serializeEmpty()
      Description copied from interface: JsonWriter
      Return true if empty collections should be serialised.
      Specified by:
      serializeEmpty in interface JsonWriter
    • serializeEmpty

      public final void serializeEmpty(boolean serializeEmpty)
      Description copied from interface: JsonWriter
      Set to serialise empty collections or not.
      Specified by:
      serializeEmpty in interface JsonWriter
    • 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 interface JsonWriter
    • path

      public final String path()
      Description copied from interface: JsonWriter
      Return the current path.
      Specified by:
      path in interface JsonWriter
    • beginArray

      public final void beginArray()
      Description copied from interface: JsonWriter
      Write array begin.
      Specified by:
      beginArray in interface JsonWriter
    • endArray

      public final void endArray()
      Description copied from interface: JsonWriter
      Write array end.
      Specified by:
      endArray in interface JsonWriter
    • emptyArray

      public final void emptyArray()
      Description copied from interface: JsonWriter
      Write empty array.
      Specified by:
      emptyArray in interface JsonWriter
    • beginObject

      public final void beginObject(PropertyNames names)
      Description copied from interface: JsonWriter
      Write object being and use the already encoded property names.
      Specified by:
      beginObject in interface JsonWriter
    • beginObject

      public final void beginObject()
      Description copied from interface: JsonWriter
      Write object begin.
      Specified by:
      beginObject in interface JsonWriter
    • endObject

      public final void endObject()
      Description copied from interface: JsonWriter
      Write object end.
      Specified by:
      endObject in interface JsonWriter
    • 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.beginObject(PropertyNames) and JsonWriter.name(int).

      Specified by:
      name in interface JsonWriter
    • 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.beginObject(PropertyNames) (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 interface JsonWriter
    • 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 interface JsonWriter
    • nullValue

      public final void nullValue()
      Description copied from interface: JsonWriter
      Write null value.
      Specified by:
      nullValue in interface JsonWriter
    • value

      public final void value(String value)
      Description copied from interface: JsonWriter
      Write a string value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(boolean value)
      Description copied from interface: JsonWriter
      Write a boolean value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(int value)
      Description copied from interface: JsonWriter
      Write an int value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(long value)
      Description copied from interface: JsonWriter
      Write a long value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(double value)
      Description copied from interface: JsonWriter
      Write a double value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(Boolean value)
      Description copied from interface: JsonWriter
      Write a Boolean value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(Integer value)
      Description copied from interface: JsonWriter
      Write an Integer value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(Long value)
      Description copied from interface: JsonWriter
      Write a Long value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(Double value)
      Description copied from interface: JsonWriter
      Write a Double value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(BigDecimal value)
      Description copied from interface: JsonWriter
      Write a BigDecimal value.
      Specified by:
      value in interface JsonWriter
    • value

      public final void value(BigInteger value)
      Description copied from interface: JsonWriter
      Write a BigInteger value.
      Specified by:
      value in interface JsonWriter
    • value

      public void value(byte[] value)
      Description copied from interface: JsonWriter
      Write binary content as base64.
      Specified by:
      value in interface JsonWriter
    • rawValue

      public void rawValue(String value)
      Description copied from interface: JsonWriter
      Write raw JSON content.
      Specified by:
      rawValue in interface JsonWriter
    • jsonValue

      public final void jsonValue(Object value)
      Description copied from interface: JsonWriter
      Write a value that could be any value.
      Specified by:
      jsonValue in interface JsonWriter
    • writeNewLine

      public final void writeNewLine()
      Description copied from interface: JsonWriter
      Write new line characters typically for x-json-stream content.
      Specified by:
      writeNewLine in interface JsonWriter
    • flush

      public final void flush()
      Description copied from interface: JsonWriter
      Flush the writer.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface JsonWriter
    • close

      public void close()
      Description copied from interface: JsonWriter
      Close the writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface JsonWriter
    • 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 interface JsonWriter