简体   繁体   English

宁静的服务没有返回正确的对象

[英]Restful service not returning right object

I have a Java Restful web service , which when called by postman returns an object which is missing attributes. 我有一个Java Restful Web服务, postman调用该服务时会返回缺少属性的对象。 The JSON objects can be seen below. JSON对象可以在下面看到。

The image below that shows the object just before it is returned in the rest function. 下图显示了对象在rest函数中返回之前的状态。 As you can see, there are the days of the week with a value in them which are not showing up in postman. 如您所见,在星期几中有一个值,这些值在邮递员中没有显示。

The backAbsence entity can be view at the end of this post. backAbsence实体可以在本文结尾处查看。

The SAbsence is a list of the backAbsence entity's. SAbsencebackAbsence实体的列表。

What I am wondering is why when i return the SAbsenece are the full models not received in postman and how do I resolve it? 我想知道的是为什么当我返回SAbsenece时邮递员没有收到完整的模型,我该如何解决?

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

在此处输入图片说明

Rest function Part: 休息功能部分:

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

}

It looks to me that whatever json mapper implementation you are using to do the conversion is only looking for java bean style getters and setters so is ignoring you int methods like isMonday(). 在我看来,无论您使用哪种json映射器实现进行转换,都只会查找java bean样式的getter和setter,因此会忽略诸如isMonday()之类的int方法。 Try changing them to getMonday() or find a different mapper implementation. 尝试将它们更改为getMonday()或找到其他映射器实现。

hrm. 人力资源部 you are using a "boolean" style getter getting for int fields. 您正在使用“布尔”风格的吸气剂来获取int字段。

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

try changing this to getMonday, getTuesday etc or changing the integers to bools. 尝试将其更改为getMonday,getTuesday等,或将整数更改为bool。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM