Class JsonGenerator

  • Direct Known Subclasses:
    MockJsonGenerator

    public abstract class JsonGenerator
    extends Object
    Abstract low-level JSON serializer.

    Implementation has no fields and therefore thread-safe, but sub-classes are not necessarily thread-safe.

    Since:
    1.3
    Author:
    Yaniv Inbar
    • Constructor Detail

      • JsonGenerator

        public JsonGenerator()
    • Method Detail

      • getFactory

        public abstract JsonFactory getFactory()
        Returns the JSON factory from which this generator was created.
      • flush

        public abstract void flush()
                            throws IOException
        Flushes any buffered content to the underlying output stream or writer.
        Throws:
        IOException
      • close

        public abstract void close()
                            throws IOException
        Closes the serializer and the underlying output stream or writer, and releases any memory associated with it.
        Throws:
        IOException
      • writeStartArray

        public abstract void writeStartArray()
                                      throws IOException
        Writes a JSON start array character '['.
        Throws:
        IOException
      • writeEndArray

        public abstract void writeEndArray()
                                    throws IOException
        Writes a JSON end array character ']'.
        Throws:
        IOException
      • writeStartObject

        public abstract void writeStartObject()
                                       throws IOException
        Writes a JSON start object character '{'.
        Throws:
        IOException
      • writeEndObject

        public abstract void writeEndObject()
                                     throws IOException
        Writes a JSON end object character '}'.
        Throws:
        IOException
      • writeFieldName

        public abstract void writeFieldName​(String name)
                                     throws IOException
        Writes a JSON quoted field name.
        Throws:
        IOException
      • writeNull

        public abstract void writeNull()
                                throws IOException
        Writes a literal JSON null value.
        Throws:
        IOException
      • writeString

        public abstract void writeString​(String value)
                                  throws IOException
        Writes a JSON quoted string value.
        Throws:
        IOException
      • writeBoolean

        public abstract void writeBoolean​(boolean state)
                                   throws IOException
        Writes a literal JSON boolean value ('true' or 'false').
        Throws:
        IOException
      • writeNumber

        public abstract void writeNumber​(int v)
                                  throws IOException
        Writes a JSON int value.
        Throws:
        IOException
      • writeNumber

        public abstract void writeNumber​(long v)
                                  throws IOException
        Writes a JSON long value.
        Throws:
        IOException
      • writeNumber

        public abstract void writeNumber​(float v)
                                  throws IOException
        Writes a JSON float value.
        Throws:
        IOException
      • writeNumber

        public abstract void writeNumber​(double v)
                                  throws IOException
        Writes a JSON double value.
        Throws:
        IOException
      • writeNumber

        public abstract void writeNumber​(String encodedValue)
                                  throws IOException
        Writes a JSON numeric value that has already been encoded properly.
        Throws:
        IOException
      • serialize

        public final void serialize​(Object value)
                             throws IOException
        Serializes the given JSON value object, or if value is null it does no serialization.
        Throws:
        IOException
      • enablePrettyPrint

        public void enablePrettyPrint()
                               throws IOException
        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.

        Throws:
        IOException - possible I/O exception (unused in default implementation)
        Since:
        1.6