【发布时间】:2019-11-16 19:39:58
【问题描述】:
我想要实现的是在自定义反序列化器中将 JsonNode 转换为 POJO(=对其进行反序列化)。
大多数其他答案建议使用对象映射器,但我在 deserialize 方法中没有。
这是我的自定义反序列化器:
class AccountDeserializer extends StdDeserializer<Input> {
public AccountDeserializer() {
this(null);
}
public AccountDeserializer(Class<?> vc) {
super(vc);
}
@Override
public Account deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode root = jp.getCodec().readTree(jp);
User user = root.get("user").????;
// other statements
Account acc = new Account(user);
return acc;
}
}
(User 是一个简单的类)
【问题讨论】: