Package com.yahoo.document.json
Class JsonWriter
java.lang.Object
com.yahoo.document.json.JsonWriter
- All Implemented Interfaces:
DocumentWriter
,FieldWriter
,com.yahoo.vespa.objects.Serializer
Serialize Document and other FieldValue instances as JSON.
- Author:
- Steinar Knutsen
-
Constructor Summary
ConstructorDescriptionJsonWriter
(com.fasterxml.jackson.core.JsonGenerator generator) JsonWriter
(com.fasterxml.jackson.core.JsonGenerator generator, boolean tensorShortForm, boolean tensorDirectValues) Create a Document writer which will write to the input JSON generator.JsonWriter
(OutputStream out) Creates a JsonWriter.JsonWriter
(OutputStream out, boolean tensorShortForm, boolean tensorDirectValues) -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
documentRemove
(DocumentId docId) 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
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[]
toByteArray
(Document document) Utility method to easily serialize a single document.static byte[]
toByteArray
(Document document, boolean tensorShortForm, boolean tensorDirectValues) Utility method to easily serialize a single document.void
Writes a document.void
write
(DocumentId id) void
write
(DocumentType type) void
write
(com.yahoo.vespa.objects.FieldBase field, AnnotationReference value) Writes the value of an annotation reference.<T extends FieldValue>
voidWrites the value of an array field.void
write
(com.yahoo.vespa.objects.FieldBase field, BoolFieldValue value) Writes the value of byte field.void
write
(com.yahoo.vespa.objects.FieldBase field, ByteFieldValue value) Writes the value of a byte field.<T extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value) Writes the value of a collection field.void
write
(com.yahoo.vespa.objects.FieldBase field, DoubleFieldValue value) Writes the value of a 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) Writes the value of a flosat field.void
write
(com.yahoo.vespa.objects.FieldBase field, IntegerFieldValue value) Writes the value of an integer collection field.void
write
(com.yahoo.vespa.objects.FieldBase field, LongFieldValue value) Writes the value of a long field.<K extends FieldValue,
V extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, MapFieldValue<K, V> map) Writes the value of a map field.void
write
(com.yahoo.vespa.objects.FieldBase field, PredicateFieldValue value) Writes the value of a predicate field.void
Writes the value of a raw field.void
write
(com.yahoo.vespa.objects.FieldBase field, ReferenceFieldValue value) Writes the value of a reference field.void
write
(com.yahoo.vespa.objects.FieldBase field, StringFieldValue value) Writes the value of a string field.void
Writes the value of a struct field.void
write
(com.yahoo.vespa.objects.FieldBase field, StructuredFieldValue value) Writes the value of a structured field.void
write
(com.yahoo.vespa.objects.FieldBase field, TensorFieldValue value) Writes the value of a tensor field.<T extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value) Writes the value of a weighted set field.void
Writes the value of a field.void
writeFields
(Document value)
-
Constructor Details
-
JsonWriter
Creates a JsonWriter.- Parameters:
out
- the target output stream- Throws:
RuntimeException
- if unable to create the internal JSON generator
-
JsonWriter
-
JsonWriter
public JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator, boolean tensorShortForm, boolean tensorDirectValues) 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 generatortensorShortForm
- whether to use the short type-dependent form for tensor valuestensorDirectValues
- whether to output tensor values directly or wrapped in a map also containing the type
-
JsonWriter
public JsonWriter(com.fasterxml.jackson.core.JsonGenerator generator)
-
-
Method Details
-
write
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 interfaceFieldWriter
- Throws:
UnsupportedOperationException
- if invoked
-
write
Description copied from interface:FieldWriter
Writes the value of a field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of an array field.- Specified by:
write
in interfaceFieldWriter
-
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
Writes the value of a map field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a byte field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of byte field.- Specified by:
write
in interfaceFieldWriter
-
write
public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value) Description copied from interface:FieldWriter
Writes the value of a collection field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a double field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a flosat field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of an integer collection field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a long field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a raw field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a predicate field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a string field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a tensor field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a reference field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a struct field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of a structured field.- Specified by:
write
in interfaceFieldWriter
-
write
public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value) Description copied from interface:FieldWriter
Writes the value of a weighted set field.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Writes the value of an annotation reference.- Specified by:
write
in interfaceFieldWriter
-
write
Description copied from interface:DocumentWriter
Writes a document.- Specified by:
write
in interfaceDocumentWriter
-
write
- Specified by:
write
in interfaceDocumentWriter
-
write
- Specified by:
write
in interfaceDocumentWriter
-
toByteArray
public static byte[] toByteArray(Document document, boolean tensorShortForm, boolean tensorDirectValues) Utility method to easily serialize a single document.- Parameters:
document
- the document to be serializedtensorShortForm
- whether tensors should be serialized in a type-dependent short formtensorDirectValues
- whether tensors should be serialized as direct values or wrapped in a map also containing the type- Returns:
- the input document serialised as UTF-8 encoded JSON
-
toByteArray
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
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 interfacecom.yahoo.vespa.objects.Serializer
-
putShort
public com.yahoo.vespa.objects.Serializer putShort(com.yahoo.vespa.objects.FieldBase field, short value) - Specified by:
putShort
in interfacecom.yahoo.vespa.objects.Serializer
-
putInt
public com.yahoo.vespa.objects.Serializer putInt(com.yahoo.vespa.objects.FieldBase field, int value) - Specified by:
putInt
in interfacecom.yahoo.vespa.objects.Serializer
-
putLong
public com.yahoo.vespa.objects.Serializer putLong(com.yahoo.vespa.objects.FieldBase field, long value) - Specified by:
putLong
in interfacecom.yahoo.vespa.objects.Serializer
-
putFloat
public com.yahoo.vespa.objects.Serializer putFloat(com.yahoo.vespa.objects.FieldBase field, float value) - Specified by:
putFloat
in interfacecom.yahoo.vespa.objects.Serializer
-
putDouble
public com.yahoo.vespa.objects.Serializer putDouble(com.yahoo.vespa.objects.FieldBase field, double value) - Specified by:
putDouble
in interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, byte[] value) - Specified by:
put
in interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, ByteBuffer value) - Specified by:
put
in interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, String value) - Specified by:
put
in interfacecom.yahoo.vespa.objects.Serializer
-
writeFields
- Throws:
IOException
-