diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index 43399024..df8bdb6d 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -162,10 +162,14 @@ private void handleStartObject() throws IOException { tokenStack.push(InternalTokenType.START_ESCAPED_OBJECT); break; case DOC_TAG: + advanceTrue(); + currentFaunaTokenType = FaunaTokenType.START_DOCUMENT; + tokenStack.push(FaunaTokenType.START_DOCUMENT); + break; case REF_TAG: case SET_TAG: throw new SerializationException( - "Token not implemented: " + jsonParser.currentToken()); + "Token not implemented: " + jsonParser.getText()); default: bufferedFaunaTokenType = FaunaTokenType.FIELD_NAME; tokenStack.push(FaunaTokenType.START_OBJECT); diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index d60c9a0d..ff7a1f5d 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -294,6 +294,37 @@ public void testReadEscapedObject() throws IOException { assertReader(reader, expectedTokens); } + @Test + public void testReadDocumentTokens() throws IOException { + String s = "{\n" + + " \"@doc\": {\n" + + " \"id\": \"123\",\n" + + " \"coll\": { \"@mod\": \"Coll\" },\n" + + " \"ts\": { \"@time\": \"2023-12-03T16:07:23.111012Z\" },\n" + + " \"data\": { \"foo\": \"bar\" }\n" + + " }\n" + + "}"; + FaunaParser reader = new FaunaParser(new ByteArrayInputStream(s.getBytes())); + + List> expectedTokens = List.of( + new AbstractMap.SimpleEntry<>(FaunaTokenType.START_DOCUMENT, null), + Map.entry(FaunaTokenType.FIELD_NAME, "id"), + Map.entry(FaunaTokenType.STRING, "123"), + Map.entry(FaunaTokenType.FIELD_NAME, "coll"), + Map.entry(FaunaTokenType.MODULE, new Module("Coll")), + Map.entry(FaunaTokenType.FIELD_NAME, "ts"), + Map.entry(FaunaTokenType.TIME, Instant.parse("2023-12-03T16:07:23.111012Z")), + Map.entry(FaunaTokenType.FIELD_NAME, "data"), + new AbstractMap.SimpleEntry<>(FaunaTokenType.START_OBJECT, null), + Map.entry(FaunaTokenType.FIELD_NAME, "foo"), + Map.entry(FaunaTokenType.STRING, "bar"), + new AbstractMap.SimpleEntry<>(FaunaTokenType.END_OBJECT, null), + new AbstractMap.SimpleEntry<>(FaunaTokenType.END_DOCUMENT, null) + ); + + assertReader(reader, expectedTokens); + } + private static void assertReader(FaunaParser reader, List> tokens) throws IOException { for (Map.Entry entry : tokens) {