使用 RestAssured JAXB 和 groovy 解析 iTunes RSS
Parse iTunes RSS using RestAssured JAXB and groovy
我想使用 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>
原来我不得不这样注释字段:
@XmlElement(namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")
public String category
我想使用 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>
原来我不得不这样注释字段:
@XmlElement(namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")
public String category