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
ConstructorsConstructorDescriptionJsonWriter(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(com.fasterxml.jackson.core.JsonGenerator generator, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) 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) JsonWriter(OutputStream out, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) -
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.Serializerput(com.yahoo.vespa.objects.FieldBase field, byte[] value) com.yahoo.vespa.objects.Serializercom.yahoo.vespa.objects.Serializerput(com.yahoo.vespa.objects.FieldBase field, ByteBuffer value) com.yahoo.vespa.objects.SerializerputByte(com.yahoo.vespa.objects.FieldBase field, byte value) com.yahoo.vespa.objects.SerializerputDouble(com.yahoo.vespa.objects.FieldBase field, double value) com.yahoo.vespa.objects.SerializerputFloat(com.yahoo.vespa.objects.FieldBase field, float value) com.yahoo.vespa.objects.SerializerputInt(com.yahoo.vespa.objects.FieldBase field, int value) com.yahoo.vespa.objects.SerializerputLong(com.yahoo.vespa.objects.FieldBase field, long value) com.yahoo.vespa.objects.SerializerputShort(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.static byte[]toByteArray(Document document, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) Utility method to easily serialize a single document.voidWrites a document.voidwrite(DocumentId id) voidwrite(DocumentRemove documentRemove) voidwrite(DocumentType type) voidwrite(DocumentUpdate documentUpdate) voidwrite(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.voidwrite(com.yahoo.vespa.objects.FieldBase field, BoolFieldValue value) Writes the value of byte field.voidwrite(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.voidwrite(com.yahoo.vespa.objects.FieldBase field, DoubleFieldValue value) Writes the value of a double field.voidwrite(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.voidwrite(com.yahoo.vespa.objects.FieldBase field, FloatFieldValue value) Writes the value of a flosat field.voidwrite(com.yahoo.vespa.objects.FieldBase field, IntegerFieldValue value) Writes the value of an integer collection field.voidwrite(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.voidwrite(com.yahoo.vespa.objects.FieldBase field, PredicateFieldValue value) Writes the value of a predicate field.voidWrites the value of a raw field.voidwrite(com.yahoo.vespa.objects.FieldBase field, ReferenceFieldValue value) Writes the value of a reference field.voidwrite(com.yahoo.vespa.objects.FieldBase field, StringFieldValue value) Writes the value of a string field.voidWrites the value of a struct field.voidwrite(com.yahoo.vespa.objects.FieldBase field, StructuredFieldValue value) Writes the value of a structured field.voidwrite(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.voidWrites the value of a field.voidwriteFields(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(OutputStream out, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) -
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. TODO: remove.- 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, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) 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 generatortensorOptions- tensor formatting options (short/long, direct/wrapped, hexdump or not)
-
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:
writein interfaceFieldWriter- Throws:
UnsupportedOperationException- if invoked
-
write
Description copied from interface:FieldWriterWrites the value of a field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of an array field.- Specified by:
writein 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:FieldWriterWrites the value of a map field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a byte field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of byte field.- Specified by:
writein interfaceFieldWriter
-
write
public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, CollectionFieldValue<T> value) Description copied from interface:FieldWriterWrites the value of a collection field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a double field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a flosat field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of an integer collection field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a long field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a raw field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a predicate field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a string field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a tensor field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a reference field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a struct field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of a structured field.- Specified by:
writein interfaceFieldWriter
-
write
public <T extends FieldValue> void write(com.yahoo.vespa.objects.FieldBase field, WeightedSet<T> value) Description copied from interface:FieldWriterWrites the value of a weighted set field.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:FieldWriterWrites the value of an annotation reference.- Specified by:
writein interfaceFieldWriter
-
write
Description copied from interface:DocumentWriterWrites a document.- Specified by:
writein interfaceDocumentWriter
-
write
- Specified by:
writein interfaceDocumentWriter
-
write
- Specified by:
writein interfaceDocumentWriter
-
write
- Specified by:
writein interfaceDocumentWriter
-
write
- Specified by:
writein interfaceDocumentWriter
-
toByteArray
public static byte[] toByteArray(Document document, boolean tensorShortForm, boolean tensorDirectValues) Utility method to easily serialize a single document. TODO: remove- 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
public static byte[] toByteArray(Document document, com.yahoo.tensor.serialization.JsonFormat.EncodeOptions tensorOptions) Utility method to easily serialize a single document.- Parameters:
document- the document to be serializedtensorOptions- tensor formatting options (short/long, direct/wrapped, hexdump or not)- 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:
putBytein interfacecom.yahoo.vespa.objects.Serializer
-
putShort
public com.yahoo.vespa.objects.Serializer putShort(com.yahoo.vespa.objects.FieldBase field, short value) - Specified by:
putShortin interfacecom.yahoo.vespa.objects.Serializer
-
putInt
public com.yahoo.vespa.objects.Serializer putInt(com.yahoo.vespa.objects.FieldBase field, int value) - Specified by:
putIntin interfacecom.yahoo.vespa.objects.Serializer
-
putLong
public com.yahoo.vespa.objects.Serializer putLong(com.yahoo.vespa.objects.FieldBase field, long value) - Specified by:
putLongin interfacecom.yahoo.vespa.objects.Serializer
-
putFloat
public com.yahoo.vespa.objects.Serializer putFloat(com.yahoo.vespa.objects.FieldBase field, float value) - Specified by:
putFloatin interfacecom.yahoo.vespa.objects.Serializer
-
putDouble
public com.yahoo.vespa.objects.Serializer putDouble(com.yahoo.vespa.objects.FieldBase field, double value) - Specified by:
putDoublein interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, byte[] value) - Specified by:
putin interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, ByteBuffer value) - Specified by:
putin interfacecom.yahoo.vespa.objects.Serializer
-
put
public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase field, String value) - Specified by:
putin interfacecom.yahoo.vespa.objects.Serializer
-
writeFields
- Throws:
IOException
-