Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

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

Closed
zpj824 opened this issue Dec 28, 2018 · 1 comment

Comments

@zpj824
Copy link

zpj824 commented Dec 28, 2018

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
@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder changed the title Can not deserialize instance of org.json.JSONArray out of FIELD_NAME token Misleading exception when trying to deserialize JSON String as org.json.JSONArray value Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants