Search code examples
groovyjaxbrssitunesrest-assured

Parse iTunes RSS using RestAssured JAXB and groovy


I want to parse RSS XML feed using JAXB and RestAssured.

The problem I encountered is that I can't deserialize elements with itunes prefix.

My model:

    @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)

And my 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>

Solution

  • It turned out that I had to annotate fields this way:

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