I'm trying to parse below code json string value:
val map1 = mapper.readValue("""{"test":"113123","myList":{"test2":"321323","test3":"11122"}}""", classOf[Map[String,Any]])
System.out.println(map1)
for that i'm getting output something like this:
Map(test -> 113123, myList -> Map(test2 -> 321323, test3 -> 11122))
But my expected output would be:
Map(test -> 113123, myList -> Some(Map(test2 -> 321323, test3 -> 11122)))
Need help to solve this problem. Thanks
if you're looking for Some()
as a value in your map, presumably there'd be some case where you'd expect a None
. Rather than the Option
be built-in to your map (perhaps with classOf(Map[String, Option[Any]])
), I would have expected an Option
to be returned on trying to access values from your map, as in Map.get("myList")
, otherwise I'm not sure how you'd define that you didn't also want Map("cat" -> None, "dog" -> None, "fish" -> None)
etc.
In short, it looks to me like the Some
is in an odd place
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.