java - How to convert JsonNode to Map -
using play framework java on server i'm using graphiql make requests, when final jsonnode variables = request().body().asjson().get("variables"), jsonnode value "{\"id\":\"bar\"}" , want convert jsonnode map, tried
json.mapper().convertvalue(variables, new typereference<hashmap<string, object>>() { }); but keep getting exception
caused by: com.fasterxml.jackson.databind.jsonmappingexception: can not instantiate value of type [map type; class java.util.hashmap, [simple type, class java.lang.string] -> [simple type, class java.lang.object]] string value ('{"id":"bar"}'); no single-string constructor/factory method @ [source: n/a; line: -1, column: -1] what doing wrongly? how convert jsonnode map?
change type reference use map interface instead of hashmap class. new typereference<map<string, object>>.
update:
also, said json node has value "{\"id\":\"bar\"}". that's not json object, that's json string. ensure whole object looks this:
{ "variables": { "id":"bar" }, "otherfields": ... } and not this:
{ "variables": "{\"id\":\"bar\"}", "otherfields": ... }
Comments
Post a Comment