struts2-json-plugin 可以接受大驼峰参数吗?

Can struts2-json-plugin accept upper camel case parameters?

我正在使用 struts2(struts2-json-插件) 来处理 Content-Type=application/json 请求,

参数样式是小驼峰式的一切都很好,比如{"region":"China","version":"v4"}

但是当params是大驼峰时,它就不能工作了,比如{"Region":"China","Version":"v4"}

我已经阅读了struts文档(https://struts.apache.org/plugins/json/),但仍然没有找到解决方法。

这是我的一部分 struts.xml:

它不能与不区分大小写的 json 对象一起使用,因为名称被翻译成区分大小写的 class 操作 class 的 Java class 变量。

json 插件包含名为 json 的拦截器,您应该将其配置为反序列化请求中的 json 内容的操作。 This 答案指向一些 class 负责 serialization/deserialization 和填充 Java 对象的实体。

If you don't want to populate the action then you should not use this interceptor. Instead manually parse the request with this or any other third party library to get the JSONObject. Or you could rewrite the interceptor and comment that code that is using JSONPopulator but deserialize the object with JSONUtil.

如果您想将 json 具有小写名称的对象转换为驼峰式,那么您应该在填充过程之前覆盖其中一个 classes 以对应于 Java class变量名。