我有这样的客户端,可以像这样对服务器进行呼叫:
Entity<RequestObject> entity = Entity.json(new RequestObject(Arrays.asList(1, 2, 3), Arrays.asList("xColumn", "yColumn")));
ClientConfig config = new ClientConfig();
config.register(JacksonJsonProvider.class);
Client client = ClientBuilder.newClient(config);
Response response = client.target("http://172.18.0.1:10000/getProductsData")
.request(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.json(entity.getEntity()), Response.class);
List<WarehouseProductData> dwsData = response.readEntity(new GenericType<List<WarehouseProductData>>(){});
client.close();
另一台服务器正在通过以下方法进行响应:
@PostMapping("/getProductsData")
public List<WarehouseProductData> greetingPost1(@RequestBody String json) {
WarehouseProductData wd = new WarehouseProductData(85654865);
wd.addData("xColumn", "value of product 85654865 for x column");
wd.addData("yColumn", "value of product 85654865 for y column");
wd.addData("the me column", "value of product 85654865 for 'the me column' column");
wd.addData("response for x", "1");
wd.addData("response for x", "2");
return Collections.singletonList(wd);
WarehauseProductData类如下:
public class WarehouseProductData {
private int agoId;
private Map<String, String> data;
public WarehouseProductData(int agoId, Map<String, String> data) {
this.agoId = agoId;
this.data = data;
}
public WarehouseProductData(int agoId) {
this.agoId = agoId;
this.data = new HashMap<>();
}
public int getAgoId() {
return agoId;
}
public void setAgoId(int agoId) {
this.agoId = agoId;
}
public Map<String, String> getData() {
return data;
}
public void setData(Map<String, String> data) {
this.data = data;
}
public void addData(String columnName, String value) {
data.put(columnName, value);
}
}
问题在于,当
List<WarehouseProductData> dwsData = response.readEntity(new GenericType<List<WarehouseProductData>>(){});
运行dwsData就像这样:
dwsData size = 1
|
--0 {WarehouseProductData}
|
-- agoId = 85654865
|
-- data = null (!!!which is incorect!!!)
那么如何解析响应才能正确获取data
字段?