Class JsonFormat

java.lang.Object
com.yahoo.tensor.serialization.JsonFormat

public class JsonFormat extends Object
Writes tensors on the JSON format used in Vespa tensor document fields: A JSON map containing a 'cells' or 'values' array. See https://docs.vespa.ai/en/reference/document-json-format.html
Author:
bratseth
  • Constructor Details

    • JsonFormat

      public JsonFormat()
  • Method Details

    • encode

      public static byte[] encode(Tensor tensor, boolean shortForm, boolean directValues)
      Serializes the given tensor value into JSON format.
      Parameters:
      tensor - the tensor to serialize
      shortForm - whether to encode in a short type-dependent format
      directValues - whether to encode values directly, or wrapped in am object containing "type" and "cells"
    • encode

      public static byte[] encode(Tensor tensor)
      Serializes the given tensor value into JSON format, in long format, wrapped in an object containing "cells" only.
    • encodeWithType

      @Deprecated public static byte[] encodeWithType(Tensor tensor)
      Deprecated.
      use #encode(#Tensor, boolean, boolean)
      Serializes the given tensor type and value into JSON format.
    • encodeShortForm

      @Deprecated public static byte[] encodeShortForm(Tensor tensor)
      Deprecated.
      use #encode(#Tensor, boolean, boolean)
      Serializes the given tensor type and value into a short-form JSON format.
    • decode

      public static Tensor decode(TensorType type, byte[] jsonTensorValue)
      Deserializes the given tensor from JSON format
    • decodeHexString

      public static double[] decodeHexString(String input, TensorType.Value valueType)
    • decodeNumberString

      public static double decodeNumberString(String input)