From 22a8ffe34636f0ceb7712377ec47c5b61e3008be Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Tue, 30 Jan 2024 22:39:29 -0300 Subject: [PATCH 1/2] Add support to Ref --- .../com/fauna/serialization/FaunaParser.java | 6 ++++-- .../fauna/serialization/FaunaParserTest.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index dba0cbf3..73fb2a96 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -170,8 +170,10 @@ private void handleStartObject() throws IOException { tokenStack.push(FaunaTokenType.START_PAGE); break; case REF_TAG: - throw new SerializationException( - "Token not implemented: " + jsonParser.getText()); + advanceTrue(); + currentFaunaTokenType = FaunaTokenType.START_REF; + tokenStack.push(FaunaTokenType.START_REF); + break; 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 a82cf936..0664c545 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -316,6 +316,24 @@ public void testReadSet() throws IOException { assertReader(reader, expectedTokens, false); } + @Test + public void testReadRef() throws IOException { + String s = "{\"@ref\": {\"id\": \"123\", \"coll\": {\"@mod\": \"Col\"}}}"; + + FaunaParser reader = new FaunaParser(new ByteArrayInputStream(s.getBytes())); + + List> expectedTokens = List.of( + new AbstractMap.SimpleEntry<>(FaunaTokenType.START_REF, null), + Map.entry(FaunaTokenType.FIELD_NAME, "id"), + Map.entry(FaunaTokenType.STRING, "123"), + Map.entry(FaunaTokenType.FIELD_NAME, "coll"), + Map.entry(FaunaTokenType.MODULE, new Module("Col")), + new AbstractMap.SimpleEntry<>(FaunaTokenType.END_REF, null) + ); + + assertReader(reader, expectedTokens, false); + } + private static void assertReader(FaunaParser reader, List> tokens, boolean assertExceptions) throws IOException { From fbcc0cc335189e243087c1917ebcd2e60a7a18d3 Mon Sep 17 00:00:00 2001 From: Pablo Chitolina Date: Wed, 31 Jan 2024 11:40:00 -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 cccf76ce..e5e4d818 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -364,7 +364,7 @@ public void testReadRef() throws IOException { new AbstractMap.SimpleEntry<>(FaunaTokenType.END_REF, null) ); - assertReader(reader, expectedTokens, false); + assertReader(reader, expectedTokens); } private static void assertReader(FaunaParser reader,