【问题标题】:Parse iTunes RSS using RestAssured JAXB and groovy使用 RestAssured JAXB 和 groovy 解析 iTunes RSS
【发布时间】:2021-08-09 11:54:58
【问题描述】:

我想使用 JAXB 和 RestAssured 解析 RSS XML 提要。

我遇到的问题是无法反序列化带有itunes前缀的元素。

我的模特:

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.NONE)
    class Rss {
        @XmlElement
        public Channel channel
    }

    @XmlAccessorType( XmlAccessType.NONE )
    class Channel {
        @XmlElement
        public String title
        @XmlElement
        public String description
        @XmlAttribute
        public String href
        @XmlElement
        public String language
        @XmlElement(name = "itunes:category")
        public String category
        @XmlElement(name = "itunes:explicit")
        public Boolean explicit
        @XmlElement(name = "itunes:author")
        public String author
        // ...
    }
        when:
        Response response = RestAssured.given().baseUri("...").contentType("application/rss+xml").when().get("...")

        then:
        def rss = response.then()
                .statusCode(200)
                .extract()
                .as(Rss.class, ObjectMapperType.JAXB)

还有我的 RSS:

  <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
      <channel>
          <title>...</title>
          <description>...</description>
          <itunes:image href="..."/>
          <itunes:category>Foo</itunes:category>
          <itunes:explicit>true</itunes:explicit>
          <itunes:author>Bar</itunes:author>
                  
      </channel>
  </rss>

【问题讨论】:

    标签: groovy jaxb rss itunes rest-assured


    【解决方案1】:

    原来我必须这样注释字段:

            @XmlElement(namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")
            public String category
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 2014-03-19
      • 2012-12-25
      相关资源
      最近更新 更多