Class JsonWriter

java.lang.Object
com.yahoo.document.json.JsonWriter
All Implemented Interfaces:
DocumentWriter, FieldWriter, com.yahoo.vespa.objects.Serializer

public class JsonWriter extends Object implements DocumentWriter
Serialize Document and other FieldValue instances as JSON.
Author:
Steinar Knutsen
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator)
    Create a Document writer which will write to the input JSON generator.
    JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator, boolean tensorShortForm)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Utility method to easily serialize a single document ID as a remove operation.
    com.yahoo.vespa.objects.Serializer
    put(com.yahoo.vespa.objects.FieldBase field, byte[] value)
     
    com.yahoo.vespa.objects.Serializer
    put(com.yahoo.vespa.objects.FieldBase field, String value)
     
    com.yahoo.vespa.objects.Serializer
    put(com.yahoo.vespa.objects.FieldBase field, ByteBuffer value)
     
    com.yahoo.vespa.objects.Serializer
    putByte(com.yahoo.vespa.objects.FieldBase field, byte value)
     
    com.yahoo.vespa.objects.Serializer
    putDouble(com.yahoo.vespa.objects.FieldBase field, double value)
     
    com.yahoo.vespa.objects.Serializer
    putFloat(com.yahoo.vespa.objects.FieldBase field, float value)
     
    com.yahoo.vespa.objects.Serializer
    putInt(com.yahoo.vespa.objects.FieldBase field, int value)
     
    com.yahoo.vespa.objects.Serializer
    putLong(com.yahoo.vespa.objects.FieldBase field, long value)
     
    com.yahoo.vespa.objects.Serializer
    putShort(com.yahoo.vespa.objects.FieldBase field, short value)
     
    static byte[]
    Utility method to easily serialize a single document.
    void
    write(Document document)
    write out a document
    void
     
    void
     
    void
    write(com.yahoo.vespa.objects.FieldBase field, AnnotationReference value)
    Write out the value of annotation data.
    <T extends FieldValue>
    void
    write(com.yahoo.vespa.objects.FieldBase field, Array<T> value)
    Write out the value of array field
    void
    write(com.yahoo.vespa.objects.FieldBase field, BoolFieldValue value)
    Write out the value of byte field
    void
    write(com.yahoo.vespa.objects.FieldBase field, ByteFieldValue value)
    Write out the value of byte field
    <T extends FieldValue>
    void
    write(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value)
    Write out the value of collection field
    void
    write(com.yahoo.vespa.objects.FieldBase field, DoubleFieldValue value)
    Write out the value of double field
    void
    write(com.yahoo.vespa.objects.FieldBase field, FieldValue value)
    This method will only be called if there is some type which is not properly supported in the API, or if something has been changed without updating this class.
    void
    write(com.yahoo.vespa.objects.FieldBase field, FloatFieldValue value)
    Write out the value of float field
    void
    write(com.yahoo.vespa.objects.FieldBase field, IntegerFieldValue value)
    Write out the value of integer field
    void
    write(com.yahoo.vespa.objects.FieldBase field, LongFieldValue value)
    Write out the value of long field
    <K extends FieldValue, V extends FieldValue>
    void
    write(com.yahoo.vespa.objects.FieldBase field, MapFieldValue<K,V> map)
    Write the value of a map field
    void
    write(com.yahoo.vespa.objects.FieldBase field, PredicateFieldValue value)
    Write out the value of predicate field
    void
    write(com.yahoo.vespa.objects.FieldBase field, Raw value)
    Write out the value of raw field
    void
    write(com.yahoo.vespa.objects.FieldBase field, ReferenceFieldValue value)
    Write out the value of the given reference field value.
    void
    write(com.yahoo.vespa.objects.FieldBase field, StringFieldValue value)
    Write out the value of string field
    void
    write(com.yahoo.vespa.objects.FieldBase field, Struct value)
    Write out the value of struct field
    void
    write(com.yahoo.vespa.objects.FieldBase field, StructuredFieldValue value)
    Write out the value of structured field
    void
    write(com.yahoo.vespa.objects.FieldBase field, TensorFieldValue value)
    Write out the value of the given tensor field value.
    <T extends FieldValue>
    void
    write(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value)
    Write out the value of weighted set field
    void
    write(com.yahoo.vespa.objects.FieldBase field, Document value)
    Write out the value of field
    void
     

    Methods inherited from class java.lang.Object

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

    • JsonWriter

      public JsonWriter(OutputStream out)
      Parameters:
      out - the target output stream
      Throws:
      RuntimeException - if unable to create the internal JSON generator
    • JsonWriter

      public JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator)
      Create a Document writer which will write to the input JSON generator. JsonWriter will not close the generator and only flush it explicitly after having written a full Document instance. In other words, JsonWriter will not take ownership of the generator.
      Parameters:
      generator - the output JSON generator
    • JsonWriter

      public JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator, boolean tensorShortForm)
  • Method Details

    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, FieldValue value)
      This method will only be called if there is some type which is not properly supported in the API, or if something has been changed without updating this class. This implementation throws an exception if it is reached.
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
      Throws:
      UnsupportedOperationException - if invoked
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, Document value)
      Description copied from interface: FieldWriter
      Write out the value of field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, Array<T> value)
      Description copied from interface: FieldWriter
      Write out the value of array field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public <K extends FieldValue, V extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, MapFieldValue<K,V> map)
      Description copied from interface: FieldWriter
      Write the value of a map field
      Specified by:
      write in interface FieldWriter
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, ByteFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of byte field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, BoolFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of byte field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value)
      Description copied from interface: FieldWriter
      Write out the value of collection field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, DoubleFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of double field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, FloatFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of float field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, IntegerFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of integer field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, LongFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of long field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, Raw value)
      Description copied from interface: FieldWriter
      Write out the value of raw field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, PredicateFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of predicate field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, StringFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of string field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, TensorFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of the given tensor field value.
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - tensor field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, ReferenceFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of the given reference field value.
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - reference field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, Struct value)
      Description copied from interface: FieldWriter
      Write out the value of struct field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, StructuredFieldValue value)
      Description copied from interface: FieldWriter
      Write out the value of structured field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value)
      Description copied from interface: FieldWriter
      Write out the value of weighted set field
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(com.yahoo.vespa.objects.FieldBase field, AnnotationReference value)
      Description copied from interface: FieldWriter
      Write out the value of annotation data.
      Specified by:
      write in interface FieldWriter
      Parameters:
      field - field description (name and data type)
      value - field value
    • write

      public void write(Document document)
      Description copied from interface: DocumentWriter
      write out a document
      Specified by:
      write in interface DocumentWriter
      Parameters:
      document - document to be written
    • write

      public void write(DocumentId id)
      Specified by:
      write in interface DocumentWriter
    • write

      public void write(DocumentType type)
      Specified by:
      write in interface DocumentWriter
    • toByteArray

      public static byte[] toByteArray(Document document)
      Utility method to easily serialize a single document.
      Parameters:
      document - the document to be serialized
      Returns:
      the input document serialised as UTF-8 encoded JSON
    • documentRemove

      public static byte[] documentRemove(DocumentId docId)
      Utility method to easily serialize a single document ID as a remove operation.
      Parameters:
      docId - the document to remove or which has been removed
      Returns:
      a document remove operation serialised as UTF-8 encoded JSON for the input document ID
    • putByte

      public com.yahoo.vespa.objects.Serializer putByte(com.yahoo.vespa.objects.FieldBase field, byte value)
      Specified by:
      putByte in interface com.yahoo.vespa.objects.Serializer
    • putShort

      public com.yahoo.vespa.objects.Serializer putShort(com.yahoo.vespa.objects.FieldBase field, short value)
      Specified by:
      putShort in interface com.yahoo.vespa.objects.Serializer
    • putInt

      public com.yahoo.vespa.objects.Serializer putInt(com.yahoo.vespa.objects.FieldBase field, int value)
      Specified by:
      putInt in interface com.yahoo.vespa.objects.Serializer
    • putLong

      public com.yahoo.vespa.objects.Serializer putLong(com.yahoo.vespa.objects.FieldBase field, long value)
      Specified by:
      putLong in interface com.yahoo.vespa.objects.Serializer
    • putFloat

      public com.yahoo.vespa.objects.Serializer putFloat(com.yahoo.vespa.objects.FieldBase field, float value)
      Specified by:
      putFloat in interface com.yahoo.vespa.objects.Serializer
    • putDouble

      public com.yahoo.vespa.objects.Serializer putDouble(com.yahoo.vespa.objects.FieldBase field, double value)
      Specified by:
      putDouble in interface com.yahoo.vespa.objects.Serializer
    • put

      public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, byte[] value)
      Specified by:
      put in interface com.yahoo.vespa.objects.Serializer
    • put

      public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, ByteBuffer value)
      Specified by:
      put in interface com.yahoo.vespa.objects.Serializer
    • put

      public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, String value)
      Specified by:
      put in interface com.yahoo.vespa.objects.Serializer
    • writeFields

      public void writeFields(Document value) throws IOException
      Throws:
      IOException