JsonUtil.parseJson("[]") results in a ClassCastException
Issue #142
closed
The result of calling JsonUtil.parseJson("[]") is:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.jose4j.json.JsonUtil$DupeKeyDisallowingLinkedHashMap
at org.jose4j.json.JsonUtil.parseJson(JsonUtil.java:62) ~[jose4j.jar:?]
The JsonUtil class assumes that the parsed JSON will result in a map, but an empty array "[]"
results in an ArrayList. This causes a ClassCastException as the Arraylist returned cannot be cast as a LinkedHashMap.
The validity of this bug depends on if you consider []
to be valid JSON, but you may want to handle this exception in any case.
Comments (5)
-
-
Account Deactivated reporter - changed status to resolved
Thanks Brian
-
repo owner - changed status to open
a better error message could be worthwhile here
-
repo owner - changed status to resolved
-
repo owner - changed status to closed
released in jose4j-0.7.0 https://bitbucket.org/b_c/jose4j/wiki/Release%20Notes#!jose4j-070-january-17-2019
- Log in to comment
It is valid JSON but JsonUtil isn’t intended to be a general JSON processor. It’s a utility in support of JOSE/JWT functionality and JOSE/JWT JSON is always an JSON Object at the root. JsonUtil is designed for that.