0

我有一个 Jersey 网络服务生成以下 JSON:

{"ConfigData":[{"@name":"Admin Component Version","@value":"version 1","@type":"String"},{"@name":"Component Version","@value":"version 1","@type":"String"}]}

从此 JAX-B 对象:

@XmlRootElement(name = "ConfigData")
public class ConfigData {

    @XmlAttribute(name = "name", required = true)
    String name;

    @XmlAttribute(name = "value", required = true)
    String value;

    @XmlAttribute(name = "type", required = true)
    String type;

    @XmlAttribute(name = "groupId", required = false)
    String groupId;
    [...]
}

我正在运行具有以下内容的单元测试:

    final WebResource webResource = resource();
    final ClientResponse response = webResource.path(
            VersionProviderTest.SERVICE_PATH).get(ClientResponse.class);
    String jsonResponse = response.getEntity(String.class);

    ObjectMapper mapper = new ObjectMapper();
    //Exception is thrown at the line below obviously
    ConfigData[] list = mapper.readValue(jsonResponse.getBytes(),ConfigData[].class);

为什么会抛出这个异常?我错过了什么?这是我第一次尝试像这样将 Jackson 用于 Marshall 和 UnMarchall 课程。好像一切都在那里...

谢谢,

4

1 回答 1

0

那么为什么不完全跳过杰克逊并直接从球衣中获取输出。默认情况下,他们显然没有使用相同的 Json 格式。

    final WebResource webResource = resource();
    final ClientResponse response = webResource.path(
            VersionProviderTest.SERVICE_PATH).get(ClientResponse.class);
    ConfigData[] list = response.getEntity(ConfigData[].class);

这就像一个魅力!

于 2013-05-16T17:41:32.353 回答