【发布时间】:2020-08-11 17:13:37
【问题描述】:
假设我有这样的类结构:-
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;
}
}
如何根据 shapeInfo.shapeName 字段值以将字段 shape 映射到 Square 或 Circle 类型的方式反序列化 ShapeRequest?
例如,下面的 JSON 应该映射到具有 Circle 形状类型的 ShapeRequest,因为 shapeInfo.shapeName = "circle"
{
"shapeInfo": {
"shapeName": "circle",
"shapeDimension": "2"
},
"shape": {
"area": 10
}
}
【问题讨论】:
标签: java spring jackson jackson-databind jackson2