生活随笔
收集整理的這篇文章主要介紹了
小技巧集锦
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
jackson JsonDeserialize 使用方法: 實現方法注解寫在set方法上。 public class CustomJsonDateDeserializer extends JsonDeserializer<Date> {private SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");@Overridepublic Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {String text = jp.getText();if (StringUtils.hasText(text)) {try {if (text.indexOf(":") == -1 && text.length() == 10) {return this.dateFormat.parse(text);} else if (text.indexOf(":") > 0 && text.length() == 19) {return this.datetimeFormat.parse(text);} else {throw new IllegalArgumentException("Could not parse date, date format is error ");}} catch (ParseException ex) {IllegalArgumentException iae = new IllegalArgumentException("Could not parse date: " + ex.getMessage());iae.initCause(ex);throw iae;}} else {return null;}}} ?
轉載于:https://my.oschina.net/u/2319418/blog/1833305
總結
以上是生活随笔為你收集整理的小技巧集锦的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。