如何解决错误代码45:使用Json ObjectMapper序列化/反序列化LocalDate springboot

时间:2018-09-10 17:37:35

标签: postman objectmapper jackson-databind localdate

以下是我收到的错误消息:

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('-' (code 45)): Expected space separating root-level values
 at [Source: (String)"2018-10-10"; line: 1, column: 6]

下面是我的 UPDATED 代码,用于读取邮递员Json的日期:{“ modifiedDate”:“ 2018-09-10”}

String modifiedDateJson = data.get("modifiedDate").asText();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dateFormat.parse(modifiedDateJson);
        String output = dateFormat.format(date);


        Date modifiedDateDf = mapper.readValue(modifiedDateJson,Date.class);
        LocalDate modifiedDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

0 个答案:

没有答案