0
    @POST
    @Path("/{companyid}/location")
    public Response addLocationCommand(LocationCommandDto addLocationCommand, @PathParam("companyid") String companyID) throws Throwable{
        addLocationCommand.setCompanyId(companyID);
        Response response = processApiRequest(addLocationCommand, LocationCommandDtoToAddLocationCommandConverter.class,
                AddLocationCommandProcessor.class);
        return response;

Now i am sending request in json format

{
    "locationNam1e": "ytjtjtyj",
    "locationType":"new",
    "timeZone":"",
    "mondayWorkingType":"halfday"
}

Now my LocationCommandDto class contains following attributes.

public class LocationCommandDto implements CommandDTO {

        private String companyId;
        private String locationName;
        private String locationType;
        private String timeZone;
}

now in json i have attribute as "locationNam1e" which is incorrect and in my LocationCommandDto it is locationName,so how to map them and throw exceptions if request body's parameter not matches to the class attribute that we are converting??

2 Answers2

0

Such thing should be configured in your ObjectMapper

ObjectMapper objectMapper = getObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
Community
  • 1
  • 1
Beri
  • 11,470
  • 4
  • 35
  • 57
0

If you're using Spring Boot you can set following property in your application.properties file:

spring.jackson.deserialization.fail-on-unknown-properties=true
sovas
  • 1,508
  • 11
  • 23