H
H
have_a_questions2017-01-23 22:34:39
Java
have_a_questions, 2017-01-23 22:34:39

How to overeat json in rest controller?

I get an error like localhost:8080/api/v1/cardLimit 400 (Bad Request); when i try to send

public class GameLimit implements Serializable {

    private static final long serialVersionUID = 1L;

    private LimitType firstLimit;
    private LimitType secondLimit;

    public LimitType getFirstLimit() {
        return firstLimit;
    }

    public void setFirstLimit(LimitType firstLimit) {
        this.firstLimit = firstLimit;
    }

    public LimitType getSecondLimit() {
        return secondLimit;
    }

    public void setSecondLimit(LimitType secondLimit) {
        this.secondLimit = secondLimit;
    }
}


public class LimitType implements Serializable{

    private static final long serialVersionUID = 1L;

    private BigDecimal limit;
    private String type;
    private String status;

    public BigDecimal getLimit() {
        return limit;
    }

    public void setLimit(BigDecimal limit) {
        this.limit = limit;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}

public class LimitReq extends GameLimit {

    private String key;

    public String getKey() {
        return key;
    }
}

Per controller:
@RequestMapping(value = "/GameLimit", method = RequestMethod.POST)
    public Response setCardLimit(@RequestBody GameLimitReq request) throws Exception {
        return limitService.updateGameLimit(request);
    }

via the angular client + typescript:
changeLimits(firstLimit: IWidgetLimit, secondLimit: IWidgetLimit, key: string): ng.IPromise<any> {
            return this.$http.post(this.apiPrefix + '/GameLimit', {
                'firstLimit': {
                    limit: firstLimit.limit,
                    type: firstLimit.type,
                    status: firstLimit.status
                },
                'secondLimit': {
                    limit: secondLimit.limit,
                    type: secondLimit.type,
                    status: secondLimit.status,
                },

                key: key
            }).then(function (response: any) {
                return response.data;
            }.bind(this));
        }

Please tell me what is wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kuznetsov, 2017-01-25
@DarkRaven

Are you using Spring Security?
If so, how do you pass the csrf token?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question