jackson1转换“YYYY-MM-DD HH🇲🇲ss”

mxlfyy 发布于 2016/08/10 09:18
阅读 1K+
收藏 0
public static void main(String[] args) {

        ObjectMapper mapper = new ObjectMapper();

        JsonDomain domain = new JsonDomain();

        String jsonStr = "{\"name\":null,\"dateTime\":\"2015-05-31 20:15:30\",\"dateString\":\"2015-05-31 20:15:30\",\"dateDate\":\"2015-05-31\"}"
try {
JsonDomain domain1 = mapper.readValue(jsonStr, JsonDomain.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



错误信息:Can not construct instance of java.util.Date from String value '2015-05-31 20:15:30': not a valid representation (error: Can not parse date "2015-05-31 20:15:30": not compatible with any of standard forms ("yyyy-MM-dd'T'HH🇲🇲ss.SSSZ", "yyyy-MM-dd'T'HH🇲🇲ss.SSS'Z'", "EEE, dd MMM yyyy HH🇲🇲ss zzz", "yyyy-MM-dd"))



加载中
0
whaon
whaon
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mapper.setDateFormat(dateFormat);
0
开不了囧
开不了囧
加上mapper.setDateFormat("yyyy-MM-dd HH:mm:ss");看看
m
mxlfyy
加上之后不带时分秒的日期没法转换啊
0
wenshao
wenshao

换fastjson吧,自动识别

https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

返回顶部
顶部