I have a JSON I am trying to deserialize. I am trying to accommodate the following structure with the following constraints
1) Both rectangle and Square are of type Shape and can instead have a list of Shapes.
2) Their ordering can be switched a Square can have a list of Rectangles (list of shapes)
3) Both Square and Rectangle could also have a list of Circle which does not inherit anything from Shape and is basically composed within Shape
4) I want to uniquely identify square and rectangle class and not treat them as the same Shape object after deserialization within my model structure(wondering if there is way without parsing the type property so I know the object type is Square or Rectangle).
{
"type": "rectangle",
"x": "3",
"y": "3",
"children": [
{
"type": "square",
"x": "3",
"y": "4",
"children": [
{
"type": "circle",
"radius": "3"
},
{
"type": "circle",
"radius": "4"
},
{
"type": "circle",
"radius": "5"
}
]
}
]
}
The model objects I created so far
abstract class Shape {
abstract val x: String
abstract val y: String
abstract val type: String
abstract val children: List<Shape>
}
data class Square(override val x: String, override val y: String, override val type: String,
override val children: List<Shape>) : Shape()
data class Rectangle(override val x: String, override val y: String, override val type:
String, override val children: List<Shape>) : Shape()
data class Circle(val radius: String, val type: String)