You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JsonObject.readFrom(String) 's javadoc says that it throws an UnsupportedOperationException but it actually throws a com.eclipsesource.json.ParseException
Description
In JsonObject either the javadoc or the code is wrong.
Seems like the javadoc and the actual exception being thrown don't match in other places.
Probably related to #8
How to reproduce it:
Running this unit test
packagecom.eclipsesource.json;
importstaticorg.junit.Assert.assertTrue;
importorg.junit.Test;
publicclassJsonObjectReadFromTest {
@Test(expected = java.lang.UnsupportedOperationException.class)
publicvoidJsonObjectReadFrom() {
JsonObjectjsonObject = JsonObject
.readFrom("This is not a JSON object");
}
@TestpublicvoidparseExceptionIsUnsupportedOperationException() {
Exceptionpex = newParseException("", 0, 0, 0);
assertTrue("ParseException is not an UnsupportedOperationException ",
pexinstanceofUnsupportedOperationException);
}
}
The result is
java.lang.Exception: Unexpected exception, expected<java.lang.UnsupportedOperationException> but was<com.eclipsesource.json.ParseException>
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
....
at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
... 15 more
The text was updated successfully, but these errors were encountered:
Throwing a ParseException is correct, because the provided string is invalid JSON. If you rewrite your test to read a valid JSON string, i.e. include quotes, then an UnsupportedOperationException is thrown:
@Test(expected = UnsupportedOperationException.class)
publicvoidJsonObjectReadFrom() {
JsonObject.readFrom("\"This is not a JSON object\"");
}
Question is if something like a "JsonTypeException" wouldn't be a better choice (see #8).
I like this library....but I found that:
JsonObject.readFrom(String)
's javadoc says that it throws anUnsupportedOperationException
but it actually throws acom.eclipsesource.json.ParseException
Description
In
JsonObject
either the javadoc or the code is wrong.the method's javadoc
readFrom(String)
saysHowever, if the input doesn't contain a JSON object it throws a
com.eclipsesource.json.ParseException
instead.lines 126-139 in
https://github.com/ralfstx/minimal-json/blob/abf82149104ff3c70142ff1062e406cbd490da45/com.eclipsesource.json/src/main/java/com/eclipsesource/json/JsonObject.java
Seems like the javadoc and the actual exception being thrown don't match in other places.
Probably related to #8
How to reproduce it:
Running this unit test
The result is
The text was updated successfully, but these errors were encountered: