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) Create a Document writer which will write to the input JSON generator.JsonWriter
(com.fasterxml.jackson.core.JsonGenerator generator, boolean tensorShortForm) JsonWriter
(OutputStream out) -
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.void
write out a documentvoid
write
(DocumentId id) void
write
(DocumentType type) void
write
(com.yahoo.vespa.objects.FieldBase field, AnnotationReference value) Write out the value of annotation data.<T extends FieldValue>
voidWrite out the value of array fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, BoolFieldValue value) Write out the value of byte fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, ByteFieldValue value) Write out the value of byte field<T extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value) Write out the value of collection fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, DoubleFieldValue value) Write out the value of double fieldvoid
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 fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, IntegerFieldValue value) Write out the value of integer fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, LongFieldValue value) Write out the value of long field<K extends FieldValue,
V extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, MapFieldValue<K, V> map) Write the value of a map fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, PredicateFieldValue value) Write out the value of predicate fieldvoid
Write out the value of raw fieldvoid
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 fieldvoid
Write out the value of struct fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, StructuredFieldValue value) Write out the value of structured fieldvoid
write
(com.yahoo.vespa.objects.FieldBase field, TensorFieldValue value) Write out the value of the given tensor field value.<T extends FieldValue>
voidwrite
(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value) Write out the value of weighted set fieldvoid
Write out the value of fieldvoid
writeFields
(Document value)
-
Constructor Details
-
JsonWriter
- 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
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
- Parameters:
field
- field description (name and data type)value
- field value- Throws:
UnsupportedOperationException
- if invoked
-
write
Description copied from interface:FieldWriter
Write out the value of field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of array field- Specified by:
write
in interfaceFieldWriter
- 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 interfaceFieldWriter
-
write
Description copied from interface:FieldWriter
Write out the value of byte field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of byte field- Specified by:
write
in interfaceFieldWriter
- 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 interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of double field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of float field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of integer field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of long field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of raw field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of predicate field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of string field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of the given tensor field value.- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- tensor field value
-
write
Description copied from interface:FieldWriter
Write out the value of the given reference field value.- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- reference field value
-
write
Description copied from interface:FieldWriter
Write out the value of struct field- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of structured field- Specified by:
write
in interfaceFieldWriter
- 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 interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:FieldWriter
Write out the value of annotation data.- Specified by:
write
in interfaceFieldWriter
- Parameters:
field
- field description (name and data type)value
- field value
-
write
Description copied from interface:DocumentWriter
write out a document- Specified by:
write
in interfaceDocumentWriter
- Parameters:
document
- document to be written
-
write
- Specified by:
write
in interfaceDocumentWriter
-
write
- Specified by:
write
in interfaceDocumentWriter
-
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
-