@Test
    public void testSparseTensor() {
        Tensor.Builder builder = Tensor.Builder.of(TensorType.fromSpec("tensor(x{},y{})"));
        builder.cell().label("x", "a").label("y", 0).value(2.0);
        builder.cell().label("x", "a").label("y", 1).value(3.0);
        builder.cell().label("x", "b").label("y", 0).value(5.0);
        builder.cell().label("x", "b").label("y", 1).value(7.0);
        Tensor tensor = builder.build();

        String shortJson = """
                {
                  "type":"tensor(x{},y{})",
                   "cells": [
                     {"address":{"x":"a","y":"0"},"value":2.0},
                     {"address":{"x":"a","y":"1"},"value":3.0},
                     {"address":{"x":"b","y":"0"},"value":5.0},
                     {"address":{"x":"b","y":"1"},"value":7.0}
                   ]
                }
                """;
        byte[] shortEncoded = JsonFormat.encode(tensor, true, false);
        assertEqualJson(shortJson, new String(shortEncoded, StandardCharsets.UTF_8));
        assertEquals(tensor, JsonFormat.decode(tensor.type(), shortEncoded));

        String longJson = """
                {
                  "type":"tensor(x{},y{})",
                  "cells":[
                    {"address":{"x":"a","y":"0"},"value":2.0},
                    {"address":{"x":"a","y":"1"},"value":3.0},
                    {"address":{"x":"b","y":"0"},"value":5.0},
                    {"address":{"x":"b","y":"1"},"value":7.0}
                  ]
                }
                """;
        byte[] longEncoded = JsonFormat.encode(tensor, false, false);
        assertEqualJson(longJson, new String(longEncoded, StandardCharsets.UTF_8));
        assertEquals(tensor, JsonFormat.decode(tensor.type(), longEncoded));

        String shortDirectJson = """
                [
                  {"address":{"x":"a","y":"0"},"value":2.0},
                  {"address":{"x":"a","y":"1"},"value":3.0},
                  {"address":{"x":"b","y":"0"},"value":5.0},
                  {"address":{"x":"b","y":"1"},"value":7.0}
                ]
                """;
        byte[] shortDirectEncoded = JsonFormat.encode(tensor, true, true);
        assertEqualJson(shortDirectJson, new String(shortDirectEncoded, StandardCharsets.UTF_8));
        assertEquals(tensor, JsonFormat.decode(tensor.type(), shortDirectEncoded));

        String longDirectJson = """
                [
                    {"address":{"x":"a","y":"0"},"value":2.0},
                    {"address":{"x":"a","y":"1"},"value":3.0},
                    {"address":{"x":"b","y":"0"},"value":5.0},
                    {"address":{"x":"b","y":"1"},"value":7.0}
                ]
                """;
        byte[] longDirectEncoded = JsonFormat.encode(tensor, false, true);
        assertEqualJson(longDirectJson, new String(longDirectEncoded, StandardCharsets.UTF_8));
        assertEquals(tensor, JsonFormat.decode(tensor.type(), longDirectEncoded));
    }
Tests parsing of various tensor values set at the root, i.e. no 'cells', 'blocks' or 'values'
vespajlib/src/test/java/com/yahoo/tensor/serialization/JsonFormatTestCase.java