Class GsonGenerator

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    class GsonGenerator
    extends JsonGenerator
    Low-level JSON serializer implementation based on GSON.

    Implementation is not thread-safe.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  GsonGenerator.StringNumber
      Hack to support numbers encoded as a string for JsonWriter.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private GsonFactory factory  
      private com.google.gson.stream.JsonWriter writer  
    • Constructor Summary

      Constructors 
      Constructor Description
      GsonGenerator​(GsonFactory factory, com.google.gson.stream.JsonWriter writer)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the serializer and the underlying output stream or writer, and releases any memory associated with it.
      void enablePrettyPrint()
      Requests that the output be pretty printed (by default it is not).
      void flush()
      Flushes any buffered content to the underlying output stream or writer.
      JsonFactory getFactory()
      Returns the JSON factory from which this generator was created.
      void writeBoolean​(boolean state)
      Writes a literal JSON boolean value ('true' or 'false').
      void writeEndArray()
      Writes a JSON end array character ']'.
      void writeEndObject()
      Writes a JSON end object character '}'.
      void writeFieldName​(java.lang.String name)
      Writes a JSON quoted field name.
      void writeNull()
      Writes a literal JSON null value.
      void writeNumber​(double v)
      Writes a JSON double value.
      void writeNumber​(float v)
      Writes a JSON float value.
      void writeNumber​(int v)
      Writes a JSON int value.
      void writeNumber​(long v)
      Writes a JSON long value.
      void writeNumber​(java.lang.String encodedValue)
      Writes a JSON numeric value that has already been encoded properly.
      void writeNumber​(java.math.BigDecimal v)
      Writes a JSON big decimal value.
      void writeNumber​(java.math.BigInteger v)
      Writes a JSON big integer value.
      void writeStartArray()
      Writes a JSON start array character '['.
      void writeStartObject()
      Writes a JSON start object character '{'.
      void writeString​(java.lang.String value)
      Writes a JSON quoted string value.
      • Methods inherited from class java.lang.Object

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

      • writer

        private final com.google.gson.stream.JsonWriter writer
    • Constructor Detail

      • GsonGenerator

        GsonGenerator​(GsonFactory factory,
                      com.google.gson.stream.JsonWriter writer)
    • Method Detail

      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from class: JsonGenerator
        Flushes any buffered content to the underlying output stream or writer.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class JsonGenerator
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: JsonGenerator
        Closes the serializer and the underlying output stream or writer, and releases any memory associated with it.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class JsonGenerator
        Throws:
        java.io.IOException
      • writeBoolean

        public void writeBoolean​(boolean state)
                          throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a literal JSON boolean value ('true' or 'false').
        Specified by:
        writeBoolean in class JsonGenerator
        Throws:
        java.io.IOException
      • writeEndArray

        public void writeEndArray()
                           throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON end array character ']'.
        Specified by:
        writeEndArray in class JsonGenerator
        Throws:
        java.io.IOException
      • writeEndObject

        public void writeEndObject()
                            throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON end object character '}'.
        Specified by:
        writeEndObject in class JsonGenerator
        Throws:
        java.io.IOException
      • writeFieldName

        public void writeFieldName​(java.lang.String name)
                            throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON quoted field name.
        Specified by:
        writeFieldName in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNull

        public void writeNull()
                       throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a literal JSON null value.
        Specified by:
        writeNull in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(int v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON int value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(long v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON long value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(java.math.BigInteger v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON big integer value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(double v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON double value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(float v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON float value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(java.math.BigDecimal v)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON big decimal value.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeNumber

        public void writeNumber​(java.lang.String encodedValue)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON numeric value that has already been encoded properly.
        Specified by:
        writeNumber in class JsonGenerator
        Throws:
        java.io.IOException
      • writeStartArray

        public void writeStartArray()
                             throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON start array character '['.
        Specified by:
        writeStartArray in class JsonGenerator
        Throws:
        java.io.IOException
      • writeStartObject

        public void writeStartObject()
                              throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON start object character '{'.
        Specified by:
        writeStartObject in class JsonGenerator
        Throws:
        java.io.IOException
      • writeString

        public void writeString​(java.lang.String value)
                         throws java.io.IOException
        Description copied from class: JsonGenerator
        Writes a JSON quoted string value.
        Specified by:
        writeString in class JsonGenerator
        Throws:
        java.io.IOException
      • enablePrettyPrint

        public void enablePrettyPrint()
                               throws java.io.IOException
        Description copied from class: JsonGenerator
        Requests that the output be pretty printed (by default it is not).

        Default implementation does nothing, but implementations may override to provide actual pretty printing.

        Overrides:
        enablePrettyPrint in class JsonGenerator
        Throws:
        java.io.IOException - possible I/O exception (unused in default implementation)