I'm having an issue with json parsing when field can have different primitive value types. For example, I can get json:
{
"name" : "john",
"age" : 31
}
Or it can be in this form:
{
"name" : "john",
"age" : "thirty one"
}
Or in this way:
{
"name" : "john",
"age" : 31.0
}
I want to be able to parse field age
to the following ADTs instances:
sealed trait PrimitiveWrapper
case class IntWrapper(v: Int) extends PrimitiveWrapper
case class StringWrapper(v: String) extends PrimitiveWrapper
case class FloatWrapper(v: Float) extends PrimitiveWrapper
So at the end I can get something like this:
case class Person(name: String, age: PrimitiveWrapper)
How can I do this? I found this topic: How to decode an ADT with circe without disambiguating objects
But in that solution we are parsing not primitive fields.