FasterXML/jackson-datatype-json-org

Misleading exception when trying to deserialize JSON String as `org.json.JSONArray` value

zpj824 opened this issue · 1 comments

public class TestDomain {
    private Integer id;
    private String name;
    private Double da;
    private LocalDateTime ldt;
    private LocalDate ld;
    private LocalTime lt;
    private JSONObject jsn;
    private JSONArray jsa;
}

execute code

public static void main(String[] args)  {

		Map map = new HashMap();
		map.put("name", "zpj");
		map.put("id", 111);
		map.put("jsa", "[1, 34, 32, \"zpj\", {\"age\": 18, \"name\": \"zpj\", \"child\": {\"name\": \"zzy\", \"gender\": \"nan\"}}, {\"url\": \"test\", \"name\": \"suhu\"}]");

		ObjectMapper om = new ObjectMapper();
		om.registerModule(new JsonOrgModule());
		TestDomain td = om.convertValue(map, TestDomain.class);
		System.out.println(td);
	}
Exception in thread "main" java.lang.IllegalArgumentException: Can not deserialize instance of org.json.JSONArray out of FIELD_NAME token
throws java.lang.IllegalArgumentException: Can not deserialize instance of org.json.JSONArray out of

Ah. The problem here is the input: value for "jsa" is String, not anything that would produce JSON Array when serialized (like Collection or array); it becomes JSON String with quotes.
Exception message is not good, however, so I will improve that a bit.