import com.fasterxml.jackson.databind.ObjectMapper;
对象转JSON:
//生成用户列表
String busiUserList = null;
if (user.getBusiUserList()!=null&&user.getBusiUserList().size()!=0) {
ObjectMapper om = new ObjectMapper() ;
//设置事件格式
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) ;
//序列化时忽略解析
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
try {
busiUserList = om.writeValueAsString(user.getBusiUserList());
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
JSON转对象
ObjectMapper mapper = new ObjectMapper();
//忽略反序列化解析异常
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
GeneralUser user = mapper.readValue(result.getContent().toString(), GeneralUser.class);