我想制造一个使用有活力的参数的APIC端点。
收到的JSON参数可考虑以下任一因素:
{
entityType: "A",
createList:[
{row: 1, name: "sted", department:"drulp"},
{row: 2, name: "mary", department:"kko"},
],
updateList:[
{row: 3, name: "sddf", department:"fff"},
{row: 4, name: "few", department:"kko"},
]
}
{
entityType: "B",
createList:[
{firstName: "John", phone: "0412345678", country:"USA"},
{firstName: "Mary", phone: "0412247474", country:"CANADA"},
],
updateList:[
{firstName: "Tim", phone: "0412345678", country:"Australia"},
{firstName: "Luke", phone: "042728282", country:"CANADA"},
]
}
综上所述,我们可以看到,不同的<代码>entityType/code>可能具有不同类型的createList
和updateList
。
现在,我正在制造一个小端点,接收这些Json数据。 我的法典如下:
主计长
@RequestMapping(method = RequestMethod.POST, value = "/import")
public void executeImport(@RequestBody ImportRequest<? extends ImportModel> request) {
// some codes...
}
<代码>ImportRequest 班级:
public class ImportRequest<T extends ImportModel> {
private String entityType;
private List<T> createList;
private List<T> updateList;
The ImportModel
class:
public abstract class ImportModel {
}
<代码>ImportTypeAModel 班级:
public class ImportTypeAModel extends ImportModel {
private Integer row;
private String name;
private String department;
// Getters and Setters
}
The ImportTypeBModel
class:
public class ImportTypeBModel extends ImportModel {
private String firstName;
private String phone;
private String country;
// Getters and Setters
}
然而,当我打电话给APIC时,它显示了以下信息:
Cannot construct instance of `com.core.domain.ImportModel` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: (PushbackInputStream); line: 1, column: 44] (through reference chain: com.core.domain.ImportRequest["createList"]->java.util.ArrayList[0])
我怎么能够创造最终点来消耗这些动态的类型参数?