I need to pass the JSON parsed map into some method which has following signature:
QUEUE.sendMsg(Map<String, String> data);
Unfortunately, I have no control on above method, and Jackson gives me parsed JSON in Map<String, Object>.
I need a Map<String, String> where
For example, if the JSON input is
{
"name" = "John",
"marked" = false,
"age" = 30,
"tags" = [ "work", "personal" ],
"meta" = { "k1" : "v1", "k2" : "v2" },
}
I want a Map<String, String> which has
map.get("name") returns "John",
map.get("marked") returns "false",
map.get("age") returns "30",
map.get("tags") returns "[ \"work\", \"personal\" ]",
map.get("meta") returns "{ \"k1\" : \"v1\", \"k2\" : \"v2\" }"
Is there any way to achieve this goal?
Unfortunately, I'm almost new to Java, and has no prior knowledge of Jackson (I have to use Jackson for this solution).
Thank you.
Yes, implicit conversions should work as long as you make sure you pass FULL type information. So something like:
Map<String,String> map = mapper.readValue(jsonSource, new TypeReference<Map<String,String>>() { });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With