我正在尝试反序列化 XML。
<server>
<url>localhost</url>
<port>8080</port>
</server>
到 POJO
class Storage {
private Server server;
}
class Server {
private String url;
private Integer port;
}
这是我的防火代码
resources = new FileInputStream("/resources/config/" + file);
mapper = new ObjectMapper();
storage = mapper.readValue(resources, Storage.class);
但它不起作用。
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
我尝试将 JAX-B 注释添加到 Storage 和 Server 类,但发生了同样的错误。
UPD
当我添加mapper = new XmlMapper();
我收到com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "url"