I have this JSON object
{
"name": "Chaitanya",
"addresses": [
{ "street": "20 ABC", "apt": "10" },
{ "street": "10 XYZ", "apt": "D3" }
]
}
Which I'm trying to deserialize into a following case class:
case class Person(
name: Option[String] = None,
addresses: Option[Seq[String]] = Some(Seq.empty)
)
addresses
field in the above case class is sequence of String where as in actual JSON it's an array of objects. When I deserialize and serialize it back using:
implicit val formats = Serialization.formats(NoTypeHints)
val parsed = parse(data).extractOpt[Person]
val str = write( parsed )
I see:
{ "name":"Chaitanya", "addresses":[] }
Is there any way I can tell json4s to keep those json objects stringified and not to parse them. Where I can expect it to be array of stingified json objects:
{
"name": "Chaitanya",
"addresses": [
"{\"street\":\"20 ABC\",\"apt\":\"10\"}",
"{\"street\":\"10 XYZ\",\"apt\":\"D3\"}"
]
}
Is there any way I can do it using custom serializer or type hint?