java - Integer can not be cast to JsonNode -
i got cast error , have no idea how solve that.
//get json file map map<string, jsonnode> cm = null; try { cm = mapper.readvalue(new file(path), map.class); } catch (jsonparseexception e) {...} //add key, value pairs map jsonnodefactory factory = jsonnodefactory.instance; objectnode node = factory.objectnode(); //add jsonnode node.putall(cm);
so exception cause 1 of key-value pairs looks this: {"id":7} , seems there no way of converting integer(7) json if 1 before.
any ideas?
the exeption:
exception in thread "main" java.lang.classcastexception: java.lang.integer cannot cast com.fasterxml.jackson.databind.jsonnode
you not specify type of keys , values in mapping:
mapper.readvalue(new file(path), map.class);
the result jackson try , map best type knows; member name, easy, it's string
; value, reads json number, json number has no decimal points, fits int
--> integer
is.
if want explicit serialization given value type, have this:
mapper.readvalue(new file(path), new typereference<map<string, jsonnode>>() {});
Comments
Post a Comment