Jackson将对象转换为json字符串时,设置默认的时间格式
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);

浙公网安备 33010602011771号