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);
|
throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
|
||||||
} catch (JsonParseException e) {
|
} catch (JsonParseException e) {
|
||||||
if (e.getCause() instanceof EOFException) {
|
if (e.getCause() instanceof EOFException) {
|
||||||
return null;
|
return JsonNull.createJsonNull();
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,17 @@ public class JsonParserTest extends TestCase {
|
|||||||
assertEquals("c", e.getAsJsonObject().get("b").getAsString());
|
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() {
|
public void testParseReader() {
|
||||||
StringReader reader = new StringReader("{a:10,b:'c'}");
|
StringReader reader = new StringReader("{a:10,b:'c'}");
|
||||||
JsonElement e = parser.parse(reader);
|
JsonElement e = parser.parse(reader);
|
||||||
|
Loading…
Reference in New Issue
Block a user