如何解决SpringBoot2:snake_case 到camelCase 负载映射通过xsd
我的应用程序在 Java8 Spring MVC 上,我正在将它迁移到 Java11 Spring Boot 应用程序。
我将来自 .xsd
文件的 Jaxb 生成类用于输入 JSON 请求的模型类,其中传入有效负载之一基于 snake_case
,生成的类位于 camelCase
中。其他端点在 CamelCase 或 PascalCase 中工作正常。
在旧版本中,输入有效载荷用于映射到模型类,但在 Spring Boot 中,我发现 snake_case 一的有效载荷属性为空。
总而言之,event_name
在 java 类中变为 eventName
并且不选择值是有效负载中的 event_name
属性。
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
...
...
<xsd:element name="sampleClassName">
<xsd:complexType>
<xsd:sequence>
...
<xsd:element name="event_name" type="xsd:string" minOccurs="1"></xsd:element>
...
</xsd:sequence>
</xsd:complexType>
</xsd:element>
...
</xsd:schema>
@XmlElement(name = "event_name",required = true)
protected String eventName;
我在 gradle 中的依赖项:
compile "com.fasterxml.jackson.core:jackson-databind:2.8.9"
xjc "com.sun.xml.bind:jaxb-impl:2.2.6"
xjc "com.sun.xml.bind:jaxb-xjc:2.2.6"
compile "javax.xml.bind:jaxb-api:2.2.6"
请提出可能出了什么问题。我参考了其他帖子并尝试了以下依赖项,但没有成功。
compile "com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.4"
compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.9.4"
compile "com.fasterxml.jackson.core:jackson-core:2.11.4"
compile "com.fasterxml.jackson.core:jackson-annotations:2.9.4"
compile "com.fasterxml.jackson.core:jackson-databind:2.11.4"
compile(group: 'com.fasterxml.jackson.dataformat',name: 'jackson-dataformat-xml',version: '2.6.3',classifier: 'javadoc')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。