生活随笔
收集整理的這篇文章主要介紹了
小技巧集锦
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
jackson JsonDeserialize 使用方法: 實(shí)現(xiàn)方法注解寫在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;}}} ?
轉(zhuǎn)載于:https://my.oschina.net/u/2319418/blog/1833305
總結(jié)
以上是生活随笔為你收集整理的小技巧集锦的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。