我有一个Jersey webservice,生成以下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);
为什么抛出此异常?我错过了什么?这是我第一次尝试将杰克逊用于Marshall和UnMarchall课程。似乎一切都在那里......
谢谢,
答案 0 :(得分:0)
那么为什么不完全跳过杰克逊并直接从球衣中获取输出。它们显然默认不使用相同的Json格式。
final WebResource webResource = resource();
final ClientResponse response = webResource.path(
VersionProviderTest.SERVICE_PATH).get(ClientResponse.class);
ConfigData[] list = response.getEntity(ConfigData[].class);
这就像一个魅力!