I do small REST service in Java.
I want to send valid request body, only with existing fields from DTO:
public class ObjectDto implements Serializable {
private static final long serialVersionUID = 1L;
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
The web service produces and consumes JSON.
@POST
@Path("/{id}/objs")
public Map<String, String> searchObject(@PathParam(NamedPathParameters.CUSTOMER_ID) String customerId,
@RequestBody ObjectDto obj)
When I test it via Postman, there is following body allowed:
{
"xcv":""
}
It is need to forbid different keys than "text". I have the feeling there was an annotation for that. Am I right? Which one? I want to avoid condition:
if(key!="test")
because there will be much more fields, not only one.