Say I have a class structure like this :-
class ShapeRequest {
ShapeInfo shapeInfo;
Shape shape;
static class ShapeInfo {
String shapeName;
String shapeDimension;
}
static abstract class Shape {
}
static class Square extends Shape{
int area;
}
static class Circle extends Shape{
int area;
}
}
How can I deserialize the ShapeRequest in a way that field shape, is mapped to Square or Circle type, depending on the shapeInfo.shapeName field value?
For example, the following JSON should map to ShapeRequest with Circle shape type, because shapeInfo.shapeName = "circle"
{
"shapeInfo": {
"shapeName": "circle",
"shapeDimension": "2"
},
"shape": {
"area": 10
}
}