I am trying to automatically deserialize json object to a scala class using Lift-Json with a coordinate class inside used to store GeoJson information.
case class Request(name:String, geometry:Geometry)
sealed abstract class Geometry
case class Point(coordinates:(Double,Double)) extends Geometry
case class LineString(coordinates:List[Point]) extends Geometry
case class Polygon(coordinates:List[LineString]) extends Geometry
I want to deserialize a json string like this:
{
name:"test",
geometry:{
"type": "LineString",
"coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}
}
into a Request case class with the right LineString runtime class in the Geometry field. I guess I should use a TypeHint but how?. Is this the correct approach or should I create three different Request (RequestPoint,RequestLineString and RequestPolygon)? This would be the Scala code to deserialize:
val json = parse(message)
json.extract[Request]