Java Jackson映射器错误
我在和警察一起工作 我使用Jackson作为解析器 我有以下字符串:Java Jackson映射器错误,java,api,jackson,Java,Api,Jackson,我在和警察一起工作 我使用Jackson作为解析器 我有以下字符串: {"close":{"day":0,"time":"2200"},"open":{"day":0,"time":"1500"}} 因此,我使用ObjectMapper: ObjectMapper mapDetail = new ObjectMapper(); Timetab timetab = mapDetail.readValue(time.get(s), Timetab.class); 其中,Timetab类是: pu
{"close":{"day":0,"time":"2200"},"open":{"day":0,"time":"1500"}}
因此,我使用ObjectMapper:
ObjectMapper mapDetail = new ObjectMapper();
Timetab timetab = mapDetail.readValue(time.get(s), Timetab.class);
其中,Timetab类是:
public class Timetab {
public static class Close{
private int day;
private String time;
public String getTime() {return time;}
public void setTime(String time) {this.time = time;}
public int getDay() {return day;}
public void setDay(int day) {this.day = day;}
}
public static class Open{
private int day;
private String time;
public int getDay() {return day;}
public void setDay(int day) {this.day = day;}
public String getTime() {return time;}
public void setTime(String time) {this.time = time;}
}
private Close cl;
private Open op;
public Close getCl() {return cl;}
public void setCl(Close cl) {this.cl = cl; }
public Open getOp() {return op;}
public void setOp(Open op) {this.op = op;}
}
我得到了以下错误:
05:38:37816错误任务UTILS$LoggingErrorHandler:95-计划任务中发生意外错误。
org.codehaus.jackson.map.exc.UnrecognizedPropertyException:无法识别的字段“close”
有人能帮我吗
谢谢Jackson将JSON属性映射到JavaBean属性。因此JSON属性
close
映射到类Timetab
中的bean属性close
,该属性不存在,因为您将bean属性命名为cl
,而不是close
请注意,bean属性的名称来自getter或setter的名称,而不是字段本身。因此,可以(但不建议)仍然有一个字段cl
:
private Close cl;
public Close getClose() { return cl; }
public void setClose(Close c) { this.cl = c; }
它不应该是“getClose”和“setClose”、“getOpen”和“setOpen”吗?