2017-04-20 51 views
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; 

对象现在我在JSON格式参数转换到REST

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

现在我LocationCommandDto类包含以下属性发送请求。

public class LocationCommandDto implements CommandDTO { 

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

在JSON我有属性为“locationNam1e”,这是不正确的,在我的LocationCommandDto是LOCATIONNAME,因此如何将它们映射并抛出异常,如果请求体的参数没有类属性的匹配,我们正在转换??

回答

0

这样的事情应该在你的ObjectMapper

ObjectMapper objectMapper = getObjectMapper(); 
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true); 
0

如果你使用Spring引导您可以按照您的application.properties文件属性设置进行配置:

spring.jackson.deserialization.fail-on-unknown-properties=true