我使用杰克逊,情景是:
我不知道如何完成此代码以使事情有效,虽然我搜遍了所有并找出了以下起点,但后来我完全堆叠了,我需要帮助......
"复杂的pojo":
public class MyPojo {
private List<MyOtherPojo> myOtherPojo;
private List<HashMap<String, String>> listOfMaps;
private Map<String, String> map;
//Constructors, getters & setters
}
客户代码:
String wsURI = "server.com/myservice?param1=a¶m2=b";
try {
URL url = new URL(wsURI);
URLConnection connection = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sbuilder = new StringBuilder();
String aux = "";
while ( (aux = in.readLine()) != null) {
sbuilder.append(aux);
}
ObjectMapper mapper = new ObjectMapper();
//TODO get myPojo object from his representation as string at sbuilder.toString();
myPojo = ???;
} catch (Exception e) {}
答案 0 :(得分:2)
解决方案感谢@peeskillet:
MyPojo myPojo = mapper.readValue(connection.getInputStream(), MyPojo.class);