Jackson XML + 不要将值包装在标签中

Jackson XML + don't wrap value in tags

嗨,杰克逊 (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;
  ...
}

您可以使用 @JacksonXmlText.

@JsonRootName("status")
class StatusDto {

    @JacksonXmlProperty(isAttribute = true)
    private Long id;

    @JacksonXmlText
    private String status;

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