我有一个Java Restful
Web服务,当postman
调用时,会返回一个缺少属性的对象。 JSON
个对象可以在下面看到。
下面的图片显示了在rest函数中返回之前的对象。正如你所看到的,有一周的日子里有一个没有出现在邮递员身上的价值。
可以在本文末尾查看backAbsence
实体。
SAbsence
是backAbsence
实体的列表。
我想知道为什么当我退回
SAbsenece
时,邮递员没有收到完整的模型,我该如何解决?
[
{
"name": "King sean",
"classidClass": 0,
"studentidStudent": 1,
"week": 14
},
{
"name": "Sean king",
"classidClass": 0,
"studentidStudent": 2,
"week": 14
}
]
休息功能部分:
@GET
@Produces({"application/xml","application/json"})
@Path("{id}/{option}")
public List<BackAbsence> findbyClass(@PathParam("id")int id,
@PathParam("option")int option) {
List<BackAbsence> SAbsence = new ArrayList<>();
// code here fills list. The Image above shows the object with valid attributes
return SAbsence;
}
}
BackAbsnece实体:
public class BackAbsence {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private int classidClass;
private int studentidStudent;
private int monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0;
private int week;
public BackAbsence() {
}
public BackAbsence(int idstudent, String name) {
this.studentidStudent = idstudent;
this.name = name;
}
public BackAbsence(int classidClass, int studentidStudent, int monday, int tuesday, int wednesday, int thursday, int friday,int week) {
this.classidClass = classidClass;
this.studentidStudent = studentidStudent;
this.monday = monday;
this.tuesday = tuesday;
this.wednesday = wednesday;
this.thursday = thursday;
this.week = week;
}
public int isMonday() {
return monday;
}
public void setMonday(int monday) {
this.monday = monday;
}
public int isTuesday() {
return tuesday;
}
public void setTuesday(int tuesday) {
this.tuesday = tuesday;
}
public int isWednesday() {
return wednesday;
}
public void setWednesday(int wednesday) {
this.wednesday = wednesday;
}
public int isThursday() {
return thursday;
}
public void setThursday(int thursday) {
this.thursday = thursday;
}
public int isFriday() {
return friday;
}
public void setFriday(int friday) {
this.friday = friday;
}
public int getClassidClass() {
return classidClass;
}
public void setClassidClass(int classidClass) {
this.classidClass = classidClass;
}
public int getStudentidStudent() {
return studentidStudent;
}
public void setStudentidStudent(int studentidStudent) {
this.studentidStudent = studentidStudent;
}
public int getWeek() {
return week;
}
public void setWeek(int week) {
this.week = week;
}
}
答案 0 :(得分:2)
在我看来,无论你用来进行转换的json mapper实现只是寻找java bean样式的getter和setter,所以忽略了像isMonday()这样的int方法。尝试将它们更改为getMonday()或查找不同的映射器实现。
答案 1 :(得分:1)
HRM。你正在使用&#34;布尔&#34;样式getter获取int字段。
private int monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0;
尝试将此更改为getMonday,getTuesday等或将整数更改为bools。