【问题标题】:Spring Rest service not returning full objectSpring Rest服务未返回完整对象
【发布时间】:2019-10-08 09:52:53
【问题描述】:

我有一个 Spring 帐户端点,如下所示,它返回一个对象数组“事物”,其中包含一些数据。出于某种原因,我只在调用时获取对象的一部分。我正在尝试检索包含完整对象的事物数组,而不仅仅是我在下面得到的奇怪的子部分。

@GetMapping("/accounts")
    public List<Things> test3() throws JSONException {
        tester.clear();
        for (int i = 0; i < 4; i++) {
            Double db = (double) i;
            Things jo = new Things(String.valueOf(i), "c", "a", java.sql.Date.valueOf("2013-09-04"),db, java.sql.Date.valueOf("2013-09-04"),
                    "d", "e", "f", "g", ko, ko);

            tester.add(jo);
        }
        return tester;

这个端点保存在一个 restController 中并返回这个:

[
    {
        "postBalance": 0.0,
        "intFromDate": "2013-09-04",
        "accType": "d",
        "accDestination": "e",
        "forexBch": "f",
        "forexAcc": "g",
        "maxLimit": 1111.0,
        "minLimit": 1111.0
    },
    {
        "postBalance": 1.0,
        "intFromDate": "2013-09-04",
        "accType": "d",
        "accDestination": "e",
        "forexBch": "f",
        "forexAcc": "g",
        "maxLimit": 1111.0,
        "minLimit": 1111.0
    },
    {
        "postBalance": 2.0,
        "intFromDate": "2013-09-04",
        "accType": "d",
        "accDestination": "e",
        "forexBch": "f",
        "forexAcc": "g",
        "maxLimit": 1111.0,
        "minLimit": 1111.0
    },
    {
        "postBalance": 3.0,
        "intFromDate": "2013-09-04",
        "accType": "d",
        "accDestination": "e",
        "forexBch": "f",
        "forexAcc": "g",
        "maxLimit": 1111.0,
        "minLimit": 1111.0
    }
]

数据类如下。

package db2New.jdbc;

import java.sql.Date;

public class Things {
    private String customerKey;
    private String ccy;
    private String sfx;
    private Date dateLastAmended;
    private Double postBalance;
    private Date intFromDate;
    private String accType;
    private String accDestination;
    private String forexBch;
    private String forexAcc;
    private Double maxLimit;
    private Double minLimit;

    public Things(String customerKey, String ccy, String sfx, Date dateLastAmended, Double postBalance,
                  Date intFromDate, String accType, String accDestination, String forexBch, String forexAcc, Double maxLimit, Double minLimit) {
        setCustomerKey(customerKey);
        setCcy(ccy);
        setSfx(sfx);
        setDateLastAmended(dateLastAmended);
        setPostBalance(postBalance);
        setIntFromDate(intFromDate);
        setAccType(accType);
        setAccDestination(accDestination);
        setForexBch(forexBch);
        setForexAcc(forexAcc);
        setMaxLimit(maxLimit);
        setMinLimit(minLimit);

    }

    private String getCustomerKey() {
        return customerKey;
    }

    public void setCustomerKey(String customerKey) {
        this.customerKey = customerKey;
    }

    private String getCcy() {
        return ccy;
    }

    public void setCcy(String ccy) {
        this.ccy = ccy;
    }

    private String getSfx() {
        return sfx;
    }

    public void setSfx(String sfx) {
        this.sfx = sfx;
    }

    private Date getDateLastAmended() {
        return dateLastAmended;
    }

    public void setDateLastAmended(Date dateLastAmended) {
        this.dateLastAmended = dateLastAmended;
    }

    public Double getPostBalance() {
        return postBalance;
    }

    public void setPostBalance(Double postBalance) {
        this.postBalance = postBalance;
    }

    public Date getIntFromDate() {
        return intFromDate;
    }

    public void setIntFromDate(Date intFromDate) {
        this.intFromDate = intFromDate;
    }

    public String getAccType() {
        return accType;
    }

    public void setAccType(String accType) {
        this.accType = accType;
    }

    public String getAccDestination() {
        return accDestination;
    }

    public void setAccDestination(String accDestination) {
        this.accDestination = accDestination;
    }

    public String getForexBch() {
        return forexBch;
    }

    public void setForexBch(String forexBch) {
        this.forexBch = forexBch;
    }

    public String getForexAcc() {
        return forexAcc;
    }

    public void setForexAcc(String forexAcc) {
        this.forexAcc = forexAcc;
    }

    public Double getMaxLimit() {
        return maxLimit;
    }

    public void setMaxLimit(Double maxLimit) {
        this.maxLimit = maxLimit;
    }

    public Double getMinLimit() {
        return minLimit;
    }

    public void setMinLimit(Double minLimit) {
        this.minLimit = minLimit;
    }

}

【问题讨论】:

    标签: java json spring rest


    【解决方案1】:

    该字段的 getter 是私有的,因此您需要更改对公共的访问权限

    【讨论】:

    • 如果我可以在这里面对手掌,我会的。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多