I'm using a RESTFUL J2EE Web Server; when my method in a resource class is consuming JSON and a there is a JSON request with extra parameters which are not defined in my java mapping object, the server throws exception.
The problem is: I DON'T WANT THE SERVER TO THROW EXCEPTION! - I just want the server to ignore the request and return an error code like '400 Bad Request'!
My method:
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createUser(final UserCreateRequest request) {
return request.getHandler().handle();
}
My Simplified Java Class:
public final class UserCreateRequest extends BaseRequest {
@JsonProperty("username")
private String username;
@JsonProperty("password")
private String password;
public final String getUsername() {
return username;
}
public final void setUsername(String username) {
this.username = username.trim().toLowerCase();
}
public final String getPassword() {
return password;
}
public final void setPassword(String password) {
this.password = password.trim();
}
@Override
@JsonIgnore
public BaseRequestHandler getHandler() {
return new UserCreateHandler(this);
}
}
Sample wrong JSON request:
{
username: "test",
password: "1234",
name: "hello"
}
In this sample the parameter 'name' is undefined!