【发布时间】: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