In my Controller, I have
@RequestParam boolean flag
This allows the caller of my API to pass "true", "yes", "on" or "1" to represent true.
However, I want to access this flag in my HandlerInterceptor
too. There, all I have is an HttpServletRequest
, and I have to access my flag as
boolean flag = Boolean.parseBoolean(request.getParameter("flag"));
This is not ideal, because parseBoolean
only considers the string "true" to be true. If the API caller passes "yes", "on" or "1" then the interceptor will treat the value as false and the controller will treat it as true.
I don't want to hard code into my application the string values that Spring considers true, because if they change in a future release we are back to square 1.
Is there a way to get consistent boolean value in both interceptor and controller?