johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ivan Greene (JIRA)" <>
Subject [jira] [Created] (JOHNZON-225) Json.createObjectBuilder(Map) cannot handle non-scalar types
Date Fri, 26 Jul 2019 15:00:00 GMT
Ivan Greene created JOHNZON-225:

             Summary: Json.createObjectBuilder(Map) cannot handle non-scalar types
                 Key: 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,

An example:
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();

This results in the exception "javax.json.JsonException: Illegal JSON type! name=quux type=class
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

View raw message