如何从JSON文件中读取Farm对象?
public class Farm(){
private Animal cat;
private String name;
private int age;
}
public class Animal(){
private int legs;
}
我使用以下代码将Farm对象写入文件。
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
mapper.writeValue(out, farmobj);
答案 0 :(得分:1)
Farm farm = mapper.readValue(new File("c:\\farm.json"), Farm.class);
您正在寻找的是什么。