0

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.

Dominika
  • 235
  • 1
  • 4
  • 14
  • 1
    Set the `DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES` to `true` as in this question http://stackoverflow.com/questions/14343477/how-do-you-globally-set-jackson-to-ignore-unknown-properties-within-spring – Ali Dehghani May 13 '16 at 20:15

1 Answers1

0

You probably mean bean validation - https://jersey.java.net/documentation/latest/bean-validation.html

Jakub Bibro
  • 1,570
  • 13
  • 17