我有一个 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 课程。好像一切都在那里...
谢谢,