Return a "JsonNull" object for empty whitespace input into the JsonParser.
This commit is contained in:
parent
fdcd3945c5
commit
b0f50bb4be
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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'}");
|
||||
|
|
Loading…
Reference in New Issue
Block a user