我試圖使用ModelMapper來映射下面的json,如http://modelmapper.org/user-manual/gson-integration/所解釋的,但是我得到一個NullPointerException,我無法確定哪裏出了什麼問題。請提供任何提示?ModelMapper:如何將這個json映射到Java?
{"a": "aaa", "b": [{"c": "ccc"}]}
public class Foo {
private String a;
private ArrayList<Bar> b;
}
public class Bar {
private String c;
}
ModelMapper mapper = new ModelMapper();
mapper.getConfiguration().addValueReader(new JsonElementValueReader());
JsonElement responseElement = new JsonParser().parse(json);
Foo foo = mapper.map(responseElement, Foo.class);
你從哪裏得到'NullPointerException'? – 2014-09-20 16:51:16
當發佈「爲什麼會出現此錯誤」類型的問題時,您需要(至少)發佈完整堆棧跟蹤,並指出代碼中的哪一行正在拋出異常。更好的辦法是發佈[SSCCE](http://sscce.org/)。 – azurefrog 2014-09-20 16:56:09
這是我得到的堆棧跟蹤:https://gist.github.com/dabd/1b84bab88144ff6bc873#file-gistfile1-txt – dmz73 2014-09-21 10:00:20