1 回答
TA贡献1821条经验 获得超4个赞
您有两种选择:
将类型更改为 或 。
internal
Document
Node
编写自定义 deserialiser,它将在行中执行与您相同的操作:
Element element = document.getDocumentElement()
;
Custom deserialiser:
class ElementDeserializer extends DOMDeserializer<Element> {
private static final long serialVersionUID = 1L;
public ElementDeserializer() {
super(Element.class);
}
@Override
public Element _deserialize(String value, DeserializationContext ctxt)
throws IllegalArgumentException {
return parse(value).getDocumentElement();
}
}
您可以按如下方式注册:
SimpleModule elementModule = new SimpleModule();
elementModule.addDeserializer(Element.class, new ElementDeserializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(elementModule);
但我建议留在定制的除甲醚 - 和 - .Documencom.fasterxml.jackson.databind.ext.DOMDeserializer.DocumentDeserializerNodecom.fasterxml.jackson.databind.ext.DOMDeserializer.NodeDeserializer
添加回答
举报