Spring MVC:客户端发送的请求在语法上是不正确的 [英] Spring MVC : The request sent by the client was syntactically incorrect

查看:1218
本文介绍了Spring MVC:客户端发送的请求在语法上是不正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当向服务器发送JSON请求时,我经常受到以下消息的欢迎:

When sending JSON requests to the server, I'm often greeted by this message:


客户端发送的请求是语法上的不正确的()。

The request sent by the client was syntactically incorrect ().

通常它是一个不正确的属性,控制器没有预料到,因为JSON映射到的对象不包含它。

Usually it's an incorrect attribute that was passed that the controller didn't expect, since the object the JSON maps to doesn't contain it.

查找参数是不必要的耗时 - 是否有办法获取更多信息,甚至是异常的堆栈跟踪?我尝试在调试模式下运行,我使用Jackson作为我的JSON(de)序列化器。

Finding the parameter is needlessly time consuming - is there a way to get more information, perhaps even a stack trace of the exception? I've tried running in debug mode and I'm using Jackson as my JSON (de)serialiser.

推荐答案

如果数据您的消费来自外部API,如果您想保护您的控制器免受您不需要的不必要的元素/属性
,您可以在POJO类上使用以下注释

If the data that your consuming is from an external api and if you want to shield your controller from unnecessary elements/properties that you dont need you can use below annotation on POJO class

@JsonIgnoreProperties(ignoreUnknown = true) 

或者你可以全局设置

//jackson 2.0
jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

这篇关于Spring MVC:客户端发送的请求在语法上是不正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆