Class DelegateJsonWriter

    • Field Detail

    • 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 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()
        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
      • 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 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 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 raw content. This is typically used to write new line characters for x-json-stream content.
        Specified by:
        writeNewLine 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