REST确保将XML响应反序列化为POJO

时间:2019-09-27 00:27:30

标签: java rest rest-assured

我正在使用REST保证的库创建一些API测试,并且当Content-Type为JSON时,可以使用以下方法将Response对象反序列化为POJO:

**Method Detail**

as

<T> T as(Class<T> cls)

Get the body and map it to a Java object. For JSON responses this requires that you have either
    Jackson, or
    Gson
in the classpath or ***for XML responses it requires JAXB to be in the classpath***.
It also requires that the response content-type is either JSON or XML or that a default parser has been been set. You can also force a specific object mapper using as(Class, ObjectMapper).

Returns:
    The object

使用一条语句:

response.getBody().as(Example.class);

但是,当尝试对XML Content-Type使用相同的方法时,会失败并创建具有空值的POJO。

我的项目使用的JDK 1.8默认包含JAXB库,并且我也尝试导入其他jaxb库(jaxb-impl,jaxb-osgi),但这也无济于事。

我试图在线查找这种情况的示例,但所有示例仅处理JSON响应。

0 个答案:

没有答案
相关问题