2014-04-01 98 views
0

我有一个Java Restful Web服务,当由postman调用时返回一个缺少属性的对象。下面可以看到JSON对象。Restful服务不返回对象

下面的图像显示了它刚刚在rest函数中返回之前的对象。正如你所看到的那样,本周的某些日子里有值得注意的东西,邮递员没有看到这些值。

backAbsence实体可以在这篇文章的末尾查看。

SAbsencebackAbsence实体的列表。

我想知道的是为什么当我返回SAbsenece是没有收到邮寄的完整模型,我该如何解决它?

[ 
    { 
     "name": "King sean", 
     "classidClass": 0, 
     "studentidStudent": 1, 
     "week": 14 
    }, 
    { 
     "name": "Sean king", 
     "classidClass": 0, 
     "studentidStudent": 2, 
     "week": 14 
    } 
] 

enter image description here

休息功能部分:

@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; 
    } 

} 

回答

1

hrm。你正在使用一个“boolean”风格getter获取int字段。

private int monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0; 

尝试改变这个getMonday,getTuesday等或改变整数为布尔值。

2

它在我看来,无论你用来做转换的json mapper实现只是寻找java bean风格的getter和setter,所以忽略你的int方法如isMonday()。尝试将它们更改为getMonday()或查找不同的映射器实现。