0
我試圖反序列化XML。FasterXML:無法將表單XML反序列化爲POJO
<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註釋添加到存儲和服務器類,但發生了同樣的錯誤。
UPD
當我添加mapper = new XmlMapper();
,我收到com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "url"
,你會很需要這些註釋,但也是一個XML映射器,而不是'ObjectMapper'。 – 2014-10-07 22:29:58
看起來像'ObjectMapper'在這裏期待JSON。 – lexicore 2014-10-07 22:30:48
已更新的問題 – Alex 2014-10-07 22:43:42