gpt4 book ai didi

java - 反序列化得到 null 字符串应该有值

转载 作者:行者123 更新时间:2023-12-01 10:29:31 25 4
gpt4 key购买 nike

我遇到了一个很奇怪的问题,如果它成为一个注意力问题,请原谅我,但我现在正在喝咖啡!

我有这个 Json:

[  
{
"address":"RS 239, Km 18,2 nº 4631 - Novo Hamburgo",
"closingTime":"06:00",
"description":"Curta como quiser.",
"distance":"6,328.35 km",
"iconUrl":"~\/Images\/Establishment\/Bar Alternativo.png",
"idEstablishment":5,
"name":"Bar Alternativo",
"openingTime":"22:30",
"phone":"(51) 3778-1820",
"type":"Casa Noturna \/ Balada"
}
]

当我尝试使用此代码反序列化此代码时:

public static ArrayList<Establishment> serializeEstablishmentList(String json) {
ObjectMapper mapper = new ObjectMapper();

ArrayList<Establishment> establishments = null;

try {
establishments = mapper.readValue(json, new TypeReference<List<Establishment>>(){});
} catch (IOException e) {
e.printStackTrace();
}

return establishments;
}

我的 distance 属性未获取其值,来自调试器的图像: debugging

这是我的建立类(class):

public class Establishment {

private long idEstablishment;
private Drawable icon;
private String iconUrl;
private String name;
private String type;
private boolean workingStatus;
private String openingTime;
private String closingTime;
private String distance;
private String phone;
private String description;
private String address;

public Establishment() {
}

public Establishment(long idEstablishment, Drawable icon, String iconUrl, String name, String type, boolean workingStatus, String openingTime, String closingTime, String distance, String phone, String description, String address) {
this.idEstablishment = idEstablishment;
this.icon = icon;
this.iconUrl = iconUrl;
this.name = name;
this.type = type;
this.workingStatus = workingStatus;
this.openingTime = openingTime;
this.closingTime = closingTime;
this.distance = distance;
this.phone = phone;
this.description = description;
this.address = address;
}

public Establishment(long id, Drawable icon, String name, boolean workingStatus, String openingTime,
String closingTime, String distance) {
this.idEstablishment = id;
this.icon = icon;
this.name = name;
this.workingStatus = workingStatus;
this.openingTime = openingTime;
this.closingTime = closingTime;
this.distance = distance;
}

public long getIdEstablishment() {
return idEstablishment;
}

public void setIdEstablishment(long idEstablishment) {
this.idEstablishment = idEstablishment;
}

public Drawable getIcon() {
return icon;
}

public void setIcon(Drawable icon) {
this.icon = icon;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean getWorkingStatus() {
return workingStatus;
}

public String getWorkingStatusLabel(){
return workingStatus ? "Aberto" : "Fechado";
}

public void setWorkingStatus(boolean workingStatus) {
this.workingStatus = workingStatus;
}

public String getOpeningTime() {
return openingTime;
}

public void setOpeningTime(String openingTime) {
this.openingTime = openingTime;
}

public String getClosingTime() {
return closingTime;
}

public void setClosingTime(String closingTime) {
this.closingTime = closingTime;
}

public String getDistance() {
return distance;
}

public void setDistance(String distance) {
this.distance = this.distance;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public boolean isWorkingStatus() {
return workingStatus;
}

public String getIconUrl() {
return iconUrl;
}

public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}
}

有什么想法吗?

最佳答案

你的setter方法是错误的:

public void setDistance(String distance) {
this.distance = this.distance;
}

这应该是:

public void setDistance(String distance) {
this.distance = distance;
}

关于java - 反序列化得到 null 字符串应该有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35163928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com