Spring Boot XML Web Service,根元素下没有属性名称

时间:2017-04-19 15:01:45

标签: xml web-services spring-boot

我在SpringBoot中有以下实体类:

@XmlRootElement(name = "on-demand-pin" )
public class OnDemandPin {

    String onDemandPin;

}

生成以下XML-Output:

<on-demand-pin><onDemandPin>1234567890</onDemandPin></on-demand-pin>

但我需要一个看起来像这样的输出:

<on-demand-pin>1234567890</on-demand-pin>

我怎样才能做到这一点?尝试了不同的注释但没有任何效果。

非常感谢任何帮助!

干杯,

1 个答案:

答案 0 :(得分:0)

一位同事发现它,我只需要这样做然后就可以了:

@XmlRootElement(name = "on-demand-pin" )
@XmlAccessorType(XmlAccessType.NONE )
public class OnDemandPin {

    @XmlValue
    private String onDemandPin;

}