diff options
Diffstat (limited to 'document')
-rw-r--r-- | document/src/main/java/com/yahoo/document/json/JsonReader.java | 3 | ||||
-rw-r--r-- | document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/JsonReader.java b/document/src/main/java/com/yahoo/document/json/JsonReader.java index adf876262fa..b6cf8c6e18b 100644 --- a/document/src/main/java/com/yahoo/document/json/JsonReader.java +++ b/document/src/main/java/com/yahoo/document/json/JsonReader.java @@ -136,7 +136,8 @@ public class JsonReader { if (null != parser.nextToken()) throw new IllegalArgumentException("expected end of input, got " + parser.currentToken()); - assert null != operation: "VespaDocumentReader should throw on missing fields"; + if (null == operation) + throw new IllegalArgumentException("document is missing the required \"fields\" field"); if (null != create) { switch (operationType) { diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index 12ccba62005..aa043a25d78 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -222,6 +222,15 @@ public class JsonReaderTestCase { } @Test + public void readDocumentWithMissingFieldsField() { + assertEquals("document is missing the required \"fields\" field", + assertThrows(IllegalArgumentException.class, + () -> createReader("{ }").readSingleDocumentStreaming(DocumentOperationType.PUT, + "id:unittest:testnull::whee")) + .getMessage()); + } + + @Test public void readSingleDocumentsPutStreaming() throws IOException { String json = """ { |