我想使用JAXB和RestAssured解析RSS提要。
我遇到的问题是我不能用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>发布于 2021-08-10 10:36:20
结果,我不得不用这种方式对字段进行注释:
@XmlElement(namespace="http://www.itunes.com/dtds/podcast-1.0.dtd")
public String categoryhttps://stackoverflow.com/questions/68711657
复制相似问题