You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Ivan Greene (JIRA)" <ji...@apache.org> on 2019/07/26 15:00:00 UTC
[jira] [Created] (JOHNZON-225) Json.createObjectBuilder(Map) cannot
handle non-scalar types
Ivan Greene created JOHNZON-225:
-----------------------------------
Summary: Json.createObjectBuilder(Map) cannot handle non-scalar types
Key: JOHNZON-225
URL: https://issues.apache.org/jira/browse/JOHNZON-225
Project: Johnzon
Issue Type: Bug
Affects Versions: 1.1.12
Reporter: Ivan Greene
Json.createObjectBuilder(Map<String, Object>) throws JsonException when passed a Map who's values are non-scalar types (JsonValue subclasses such as JsonArray/JsonObject are permitted, however).
An example:
{code:java}
@Test
public void shouldBuildJsonObjectFromMap() {
Map<String, Object> map = new HashMap<>();
map.put("foo", "bar");
map.put("baz", new HashMap<>());
map.put("quux", new ArrayList<>());
JsonObject build = Json.createObjectBuilder(map).build();
assertThat(build.getJsonObject("baz")).isNotNull();
}
{code}
This results in the exception "javax.json.JsonException: Illegal JSON type! name=quux type=class java.util.ArrayList"
This is not a problem in Yasson. The spec mentions that IllegalArgumentException should be thrown if a value from the map cannot be converted to the corresponding JsonValue, but in this case Maps or Lists should be converted to JsonObject or JsonArray
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)