Java 参数转换为REST中的对象

Java 参数转换为REST中的对象,java,rest,Java,Rest,现在我以json格式发送请求 @POST @Path("/{companyid}/location") public Response addLocationCommand(LocationCommandDto addLocationCommand, @PathParam("companyid") String companyID) throws Throwable{ addLocationCommand.setCompanyId(companyID);

现在我以json格式发送请求

    @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;
现在,我的LocationCommandDto类包含以下属性

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

现在在json中,我的属性为“locationNam1e”,这是不正确的,而在我的LocationCommandDto中,它是locationName,那么如果请求体的参数与我们正在转换的class属性不匹配,如何映射它们并抛出异常呢

应该在您的


如果您使用的是Spring Boot,则可以在application.properties文件中设置以下属性:

ObjectMapper objectMapper = getObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
ObjectMapper objectMapper = getObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
spring.jackson.deserialization.fail-on-unknown-properties=true