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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM