public static void serializeTensorField(JsonGenerator generator, FieldBase field, TensorFieldValue value,
                                            JsonFormat.EncodeOptions tensorOptions) {
        wrapIOException(() -> {
            fieldNameIfNotNull(generator, field);
            if (value.getTensor().isPresent()) {
                Tensor tensor = value.getTensor().get();
                byte[] encoded = JsonFormat.encode(tensor, tensorOptions);
                generator.writeRawValue(new String(encoded, StandardCharsets.UTF_8));
            }
            else {
                generator.writeStartObject();
                generator.writeEndObject();
            }
        });
    }
@author Steinar Knutsen
@author Vegard Sjonfjell
document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java