我正在使用 GSON 将 Java 模型转换为 JSON,以便可以将其存储在 Windows Azure Mobile 上。这是我用注释、getter 和 setter 创建的模型。但是它没有被存储。执行此操作时是否应遵循特殊的命名约定?
public class Alarm
{
@com.google.gson.annotations.SerializedName("id")
private int alarmId;
@com.google.gson.annotations.SerializedName("completed")
private Boolean completed;
@com.google.gson.annotations.SerializedName("time")
private String time;
@com.google.gson.annotations.SerializedName("days")
private int days;
@com.google.gson.annotations.SerializedName("alarm_status")
private String alarmStatus;
@com.google.gson.annotations.SerializedName("alarm_name")
private String alarmName;
@com.google.gson.annotations.SerializedName("milliseconds")
private int milliseconds;
@com.google.gson.annotations.SerializedName("filename")
private String filename;
/*
@com.google.gson.annotations.SerializedName("requester_id")
private String requesterId;
@com.google.gson.annotations.SerializedName("requestee_id")
private String requesteeId;
@com.google.gson.annotations.SerializedName("file_format")
private String fileFormat;
@com.google.gson.annotations.SerializedName("date_set")
private String dateSet;
public Alarm()
{
}
/**
* Getters and setters
*
*/
public int getAlarmId() {
return alarmId;
}
public void setAlarmId(int alarmId) {
this.alarmId = alarmId;
}
public Boolean getCompleted() {
return completed;
}
public void setCompleted(Boolean completed) {
this.completed = completed;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getDays() {
return days;
}
public void setDays(int days) {
this.days = days;
}
public String getStatus() {
return alarmStatus;
}
public void setStatus(String status) {
this.alarmStatus= status;
}
public String getName() {
return alarmName;
}
public void setName(String name) {
this.alarmName = name;
}
public int getMilliseconds() {
return milliseconds;
}
public void setMilliseconds(int milliseconds) {
this.milliseconds = milliseconds;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getRequesterId() {
return requesterId;
}
public void setRequesterId(String requesterId) {
this.requesterId = requesterId;
}
public String getDateSet() {
return dateSet;
}
public void setDateSet(String dateSet) {
this.dateSet = dateSet;
}
public String getRequesteeId() {
return requesteeId;
}
public void setRequesteeId(String requesteeId) {
this.requesteeId = requesteeId;
}
public String getFileFormat() {
return fileFormat;
}
public void setFileFormat(String fileFormat) {
this.fileFormat = fileFormat;
}
@Override
public boolean equals(Object o) {
return o instanceof Alarm && ((Alarm) o).alarmId == alarmId;
}
}