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