杰克逊XML +不会在标签中包装价值

时间:2015-02-27 16:33:35

标签: java xml jackson

您可以使用以下

更改Jackson(XML)
<?xml version='1.0' encoding='UTF-8'?>
<status id="1" count="5471">
  <status>Finished</status>
</status>

改为:

<?xml version='1.0' encoding='UTF-8'?>
<status id="1" count="5471">Finished</status>

我的代码如下所示:

@JsonRootName("status")
public class StatusDto {

  @JacksonXmlProperty(isAttribute = true)
  private Long id;

  private String status;

  @JacksonXmlProperty(isAttribute = true)
  private Integer count;
  ...
}

1 个答案:

答案 0 :(得分:3)

您可以使用@JacksonXmlText

@JsonRootName("status")
class StatusDto {

    @JacksonXmlProperty(isAttribute = true)
    private Long id;

    @JacksonXmlText
    private String status;

    @JacksonXmlProperty(isAttribute = true)
    private Integer count;
}