如何从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);
最佳答案
Farm farm = mapper.readValue(new File("c:\\farm.json"), Farm.class);
就是您要的东西。
关于java - 如何使用Jackson读取Java中的包装器类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44023495/