java—如何在使用spring引导框架的请求后主体节点中接受pascalcase而不是camelcase

sycxhyv7  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(263)

我正在使用spring框架开发restapi。我设置了一个后控制器:

@PostMapping(path="/v2/document", consumes= {"application/xml","application/json"}, produces={"application/xml","application/json"})
@ResponseBody
public ResponseEntity<Object> postDocument(HttpServletRequest request,@RequestBody Template template) throws Exception

它接受一个模板对象:公共类模板{

@XmlElement(name = "Callback")  
private String Callback;

@XmlElement(name = "OutputFormat")  
private String OutputFormat;

@XmlElement(name = "Data")  
private byte[] Data;

@XmlElement(name = "ConnectionString")  
private String ConnectionString;

@XmlElement(name = "Format")    
private String Format;

@XmlElementWrapper(name="Properties")
@XmlElement(name = "Property")
private Property[] Properties;

现在这是一个有效的请求主体:

<Template>
    <connectionString>ConString</connectionString>
    <outputFormat>pdf</outputFormat>
     <datasources>
        <datasource>
                <connectionString>ConString</connectionString>
        </datasource>
    </datasources>
</Template>

其中,外部标记是正确的pascalcase格式,但内部标记必须是camelcase格式。这就是我想让身体看起来的样子:

<Template>
    <ConnectionString>ConString</ConnectionString>
    <OutputFormat>pdf</OutputFormat>
     <Datasources>
        <Datasource>
                <ConnectionString>ConString</ConnectionString>
        </Datasource>
    </Datasources>
</Template>
yhuiod9q

yhuiod9q1#

我要做的就是加上:

@XmlRootElement(name="Template")
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
public class Template{

现在它按我想要的方式工作。

相关问题