如何在JAVA中使用泛型参数对Json对象进行deerialize

时间:2018-05-20 12:43:31

标签: java json gson

我有以下JSON,其中参数“ -LCxUVIOiLT4TUM4Os3U ”和“ -LCxUVMI85eea0kISlc5 ”是动态参数,即它永远不会是相同的参数名称(它是Firebase实时数据库数据库的ID)

{

  "compliant" : {
    "emails" : {
      "-LCxUVIOiLT4TUM4Os3U" : {
        "date" : "2018-05-19T20:35:23.483Z",
        "email" : "test@hotmail.com",
        "messageId" : "d39126a2-29b0-5702-b0a5-75d8a57b0a1d",
        "notificationType" : "Complaint"
      },
      "-LCxUVMI85eea0kISlc5" : {
        "date" : "2018-05-19T12:00:10.527Z",
        "email" : "test2@hotmail.com",
        "messageId" : "5b2ee1af-87c0-5aa3-ace3-b2d593ca7cb3",
        "notificationType" : "Complaint"
      }
    }
  }
}

如何操作此参数并在JAVA对象中反序列化?

我做过几次测试,但没有一次测试结果为阳性。

注意:我正在使用Gson。

更新 分类:

package tv.zoome.integration.data;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Email {

@SerializedName("date")
@Expose
private String date;
@SerializedName("email")
@Expose
private String email;
@SerializedName("messageId")
@Expose
private String messageId;
@SerializedName("notificationType")
@Expose
private String notificationType;

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getMessageId() {
return messageId;
}

public void setMessageId(String messageId) {
this.messageId = messageId;
}

public String getNotificationType() {
return notificationType;
}

public void setNotificationType(String notificationType) {
this.notificationType = notificationType;
}

}

0 个答案:

没有答案