【发布时间】:2019-03-29 04:53:09
【问题描述】:
我正在尝试创建一个 java 应用程序,但我对 gson API 中的一个函数有疑问。为什么这行代码生成一个空的json文件却没有任何错误显示?
重现此问题的示例对象:
public class Employee {
private String name;
private String occupation;
public Employee(String name, String occupation) {
super();
this.name = name;
this.occupation = occupation;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}
//this refers to a simple java object that works with gson
gson.toJson(this, new FileWriter(new File("somefile.json")));
【问题讨论】:
-
你有什么错误吗?
-
发布更多代码
-
不,我没有任何错误。我会尝试发布更多代码