ResponseEntity<String> stringResponseEntity = new RestTemplate().postForEntity("http://1.1.1.1:9080/xservices-node/nodeApi/getMachineServers", stringHttpEntity, String.class);
System.out.println(stringResponseEntity.getBody());
ObjectMapper objectMapper = new ObjectMapper();
//设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//禁止使用int代表Enum的order()來反序列化Enum,非常危險
objectMapper.configure(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, true);
JavaType javaType = objectMapper.getTypeFactory().constructParametrizedType(ArrayList.class, LinkedHashMap.class, XsNodeVersion.class);
try {
List list = objectMapper.readValue(stringResponseEntity.getBody(), javaType);
System.out.println(list);
} catch (IOException e) {
e.printStackTrace();
}
网友评论