Return a "JsonNull" object for empty whitespace input into the JsonParser.

This commit is contained in:
Joel Leitch 2009-09-23 19:00:05 +00:00
parent fdcd3945c5
commit b0f50bb4be
2 changed files with 12 additions and 1 deletions

View File

@ -63,7 +63,7 @@ public final class JsonParser {
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
} catch (JsonParseException e) {
if (e.getCause() instanceof EOFException) {
return null;
return JsonNull.createJsonNull();
} else {
throw e;
}

View File

@ -46,6 +46,17 @@ public class JsonParserTest extends TestCase {
assertEquals(10, e.getAsJsonObject().get("a").getAsInt());
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
}
public void testParseEmptyString() {
JsonElement e = parser.parse("\" \"");
assertTrue(e.isJsonPrimitive());
assertEquals(" ", e.getAsString());
}
public void testParseEmptyWhitespaceInput() {
JsonElement e = parser.parse(" ");
assertTrue(e.isJsonNull());
}
public void testParseReader() {
StringReader reader = new StringReader("{a:10,b:'c'}");