JSONObject.toJSONString 过滤掉值为空的key,若不需要过滤,需要用到fastjson的SerializerFeature序列化属性
public Token policyBigDate(String token,Map<String, Object> map){
Token ken = null;
try {
String url= new PropertiesTool("config.properties").getProperty("webservicePolicyBigDataSmartCareURL");
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
header.set("x-access-token", token);
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<Map<String, Object>>(map,header);
JSONObject postForObject = restTemplate.postForObject(url, httpEntity, JSONObject.class);
String response = postForObject.toJSONString(postForObject,SerializerFeature.WriteMapNullValue);
ken = FastJsonUtil.toBean(response,Token.class);
}catch (Exception e) {
logger.error("失败:", e);
}
return ken;
}
fastJson使用toJSONString()时自动过滤掉值为null
JSONObject.toJSONString(result,SerializerFeature.WriteMapNullValue);