在RESTful Web服务中生成JSON(获得WEIRD OUTPUT)

时间:2017-07-19 02:29:17

标签: java json web-services jax-rs cxf

我在制作JSON时遇到了麻烦。我可能会犯很傻的错误。 这是我的代码

    @GET
    @Path("/{accountid}")
    @Produces({MediaType.APPLICATION_JSON})
    @Consumes({"application/x-www-form-urlencoded"})

    public List<Statement> getStatementsList(@PathParam("accountid") String account) throws Exception {

        Date fromDate = new Date();
        Date toDate = new Date();
        Calendar today = Calendar.getInstance();
        toDate = today.getTime();
        today.add(Calendar.MONTH, -13);
        fromDate = today.getTime();
        ArrayList<Statement> statements = (ArrayList<Statement>) getStatements(account, null, toDate);
        return  statements;
    }

这是我的Statement类

package au.com.fxa.sfdc.Model;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Statement
{
    private Date statementDate;
    private BigDecimal totalAmount;
    private String imageLocation;
    private String accountNumber;


    public Statement() {

    }

    public Date getStatementDate()
    {
        return this.statementDate;
    }

    public String getFormattedStatementDate()
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(this.statementDate);
    }

    public BigDecimal getTotalAmount()
    {
        return this.totalAmount;
    }

    public void setStatementDate(Date statementDate)
    {
        this.statementDate = statementDate;
    }

    public void setTotalAmount(BigDecimal totalAmount)
    {
        this.totalAmount = totalAmount;
    }

    public String getImageLocation()
    {
        return this.imageLocation;
    }

    public void setImageLocation(String imageLocation)
    {
        this.imageLocation = imageLocation;

    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }


    public String toString() {
        return "au.com.fxa.s21.custdoc.model.StatementBean{" +

                ", statementDate=" + statementDate +
                ", totalAmount=" + totalAmount +
                ", imageLocation='" + imageLocation + "'" +
                "}";
    }

}

我的声明列表中有15个项目。但是我没有使用JSON,而是在浏览器中获得以下输出

   No message body writer has been found for class java.util.ArrayList, ContentType: application/json

0 个答案:

没有答案