我有自己的自定义反序列化器
@Override
public Map<String, Car<?, ?>> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonNode carsNode = p.getCodec().readTree(p);
Map<String, Car<?, ?>> CarsMap = new HashMap<String, Car<?, ?>>();
ObjectMapper mapper = new ObjectMapper();
for (JsonNode node : carsNode) {
CarsMap.put(node.get("name").asText(), mapper.readValue(node.asText(), Car.class));
}
return CarsMap;
}
认为这不起作用,因为Car
它是一个基类,并且地图应该有地图字符串,汽车的子类)
输入 JSON = [{"name": "honda", "type": "Regular , "speed": 60}]
这应该在地图中,例如Map.put("honda", RegularCar.class)