From d88c7a8b5d637cbd098d5f474cec71d3295339cc Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Tue, 30 Jan 2024 22:31:54 -0300 Subject: [PATCH 1/2] Add support to Document --- .../com/fauna/serialization/FaunaParser.java | 6 ++++- .../fauna/serialization/FaunaParserTest.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index 3705ed54..dba0cbf3 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -164,8 +164,12 @@ private void handleStartObject() throws IOException { currentFaunaTokenType = FaunaTokenType.START_DOCUMENT; tokenStack.push(FaunaTokenType.START_DOCUMENT); break; - case REF_TAG: case SET_TAG: + advanceTrue(); + currentFaunaTokenType = FaunaTokenType.START_PAGE; + tokenStack.push(FaunaTokenType.START_PAGE); + break; + case REF_TAG: throw new SerializationException( "Token not implemented: " + jsonParser.getText()); default: diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index b8bfc255..a82cf936 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -292,6 +292,30 @@ public void testReadDocumentTokens() throws IOException { assertReader(reader, expectedTokens, false); } + @Test + public void testReadSet() throws IOException { + String s = "{\n" + + " \"@set\": {\n" + + " \"data\": [{\"@int\": \"99\"}],\n" + + " \"after\": \"afterme\"\n" + + " }\n" + + "}"; + FaunaParser reader = new FaunaParser(new ByteArrayInputStream(s.getBytes())); + + List> expectedTokens = List.of( + new AbstractMap.SimpleEntry<>(FaunaTokenType.START_PAGE, null), + Map.entry(FaunaTokenType.FIELD_NAME, "data"), + new AbstractMap.SimpleEntry<>(FaunaTokenType.START_ARRAY, null), + Map.entry(FaunaTokenType.INT, 99), + new AbstractMap.SimpleEntry<>(FaunaTokenType.END_ARRAY, null), + Map.entry(FaunaTokenType.FIELD_NAME, "after"), + Map.entry(FaunaTokenType.STRING, "afterme"), + new AbstractMap.SimpleEntry<>(FaunaTokenType.END_PAGE, null) + ); + + assertReader(reader, expectedTokens, false); + } + private static void assertReader(FaunaParser reader, List> tokens, boolean assertExceptions) throws IOException { From 418eaee823ce200bc9f8d82b4a9098e20f4251a1 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Wed, 31 Jan 2024 11:38:28 -0300 Subject: [PATCH 2/2] Improved test cases --- .../src/test/java/com/fauna/serialization/FaunaParserTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index e7a4f547..7d5d9cb5 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -346,7 +346,7 @@ public void testReadSet() throws IOException { new AbstractMap.SimpleEntry<>(FaunaTokenType.END_PAGE, null) ); - assertReader(reader, expectedTokens, false); + assertReader(reader, expectedTokens); } private static void assertReader(FaunaParser reader,