maven需要的依赖:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
具体代码
ObjectMapper mapper = new ObjectMapper();
DateFormat dateformat= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mapper.setDateFormat(dateformat);//设置时间格式
mapper.setSerializationInclusion(Include.NON_NULL); //序列化时忽略null
//content是Object对象
String str = mapper.writeValueAsString(content);