Michael Fadhl
Michael Fadhl

Reputation: 11

How can I use @CookieValue in a Parameter Object Class?

Is it possible to put @CookieValue in a parameter object? I can't seem to get this to work whats is missing?

@RequestMapping(value = "/Users", method = RequestMethod.GET)
@ResponseBody
public Response getAllActiveUsers(CookieParameters parameterObject) {

  return getUserImpl.getAllActiveUsers(parameterObject.userToken,
                 parameterObject.loggedInUserId);
}

Here is the parameter object class.

public class CookieParameters {
public String userToken;
public String loggedInUserId;

public CookieParameter(
    @CookieValue(value = "Token", defaultValue = "") final String userToken,
    @CookieValue(value = "LoggedInUserId", defaultValue = "") final String  loggedInUserId) {
    this.userToken = userToken;
    this.loggedInUserId = loggedInUserId;
}

Upvotes: 1

Views: 794

Answers (1)

CodeChimp
CodeChimp

Reputation: 8154

I do not think this is possible. From my understanding, the @CookieValue can only be put on the parameters of a handler method. I think you would have to grab the @CookieValue and put them in your parameter object manually.

Upvotes: 1

Related Questions