diff --git a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java index 492c89ab..5254f962 100644 --- a/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java +++ b/faunaJava/src/main/java/com/fauna/serialization/FaunaParser.java @@ -93,6 +93,12 @@ public boolean read() throws IOException { case START_OBJECT: handleStartObject(); break; + case VALUE_TRUE: + currentFaunaTokenType = FaunaTokenType.TRUE; + break; + case VALUE_FALSE: + currentFaunaTokenType = FaunaTokenType.FALSE; + break; default: throw new SerializationException( "Unhandled JSON token type " + currentToken + "."); @@ -186,4 +192,12 @@ public Integer getValueAsInt() { throw new RuntimeException("Error getting the current token as Integer", e); } } + + public Boolean getValueAsBoolean() { + try { + return jsonParser.getValueAsBoolean(); + } catch (IOException e) { + throw new SerializationException("Error getting the current token as Boolean", e); + } + } } \ No newline at end of file diff --git a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java index eba77d26..7d1e896f 100644 --- a/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java +++ b/faunaJava/src/test/java/com/fauna/serialization/FaunaParserTest.java @@ -59,6 +59,30 @@ public void testUnexpectedEndDuringAdvance() throws IOException { assertThrows(SerializationException.class, reader::read); } + @Test + public void testGetValueAsBooleanTrue() throws IOException { + InputStream inputStream = new ByteArrayInputStream("true".getBytes()); + FaunaParser reader = new FaunaParser(inputStream); + + List> expectedTokens = List.of( + Map.entry(FaunaTokenType.TRUE, true) + ); + + assertReader(reader, expectedTokens); + } + + @Test + public void testGetValueAsBooleanFalse() throws IOException { + InputStream inputStream = new ByteArrayInputStream("false".getBytes()); + FaunaParser reader = new FaunaParser(inputStream); + + List> expectedTokens = List.of( + Map.entry(FaunaTokenType.FALSE, false) + ); + + assertReader(reader, expectedTokens); + } + private static void assertReader(FaunaParser reader, List> tokens) throws IOException { for (Map.Entry entry : tokens) { @@ -75,6 +99,10 @@ private static void assertReader(FaunaParser reader, case INT: assertEquals(entry.getValue(), reader.getValueAsInt()); break; + case TRUE: + case FALSE: + assertEquals(entry.getValue(), reader.getValueAsBoolean()); + break; default: assertNull(entry.getValue() == null); break;