summaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java4
1 files changed, 4 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java
index 01da45c67aa..c73ff03a0eb 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/JsonFormat.java
@@ -58,6 +58,7 @@ public class JsonFormat {
}
/** Deserializes the given tensor from JSON format */
+ // NOTE: This must be kept in sync with com.yahoo.document.json.readers.TensorReader in the document module
public static Tensor decode(TensorType type, byte[] jsonTensorValue) {
Tensor.Builder builder = Tensor.Builder.of(type);
Inspector root = new JsonDecoder().decode(new Slime(), jsonTensorValue).get();
@@ -66,6 +67,8 @@ public class JsonFormat {
decodeCells(root.field("cells"), builder);
else if (root.field("values").valid())
decodeValues(root.field("values"), builder);
+ else if (builder.type().dimensions().stream().anyMatch(d -> d.isIndexed())) // sparse can be empty
+ throw new IllegalArgumentException("Expected a tensor value to contain either 'cells' or 'values'");
return builder.build();
}
@@ -102,4 +105,5 @@ public class JsonFormat {
indexedBuilder.cellByDirectIndex(index.next(), value.asDouble());
});
}
+
}