java unmarshall LocalDateTime error

大兔子大兔子 提交于 2019-12-06 09:39:48

Probably you're using LocalDateTime from Java 8. This class has not any constructor for string.

In the example which you're following LocalDateTime is from JodaTime.

So, you can do this in to ways:

  • Import org.joda.time.LocalDateTime (you will need JodaTime dependency) instead of java.time.LocalDateTime;

  • or change unmarshal method to something like this:

    @Override
    public LocalDateTime unmarshal(String v) throws Exception {
        return LocalDateTime.parse(v);
    }
    

You may need to inform the date time format, as the default is a format to 2011-12-03T10:15:30, maybe this:

@Override
public LocalDateTime unmarshal(String v) throws Exception {
    return LocalDateTime.parse(v, DateTimeFormatter.ISO_INSTANT);
}

Also, in java.time.LocalDateTime toString will output one of the following ISO-8601 formats:

  • uuuu-MM-dd'T'HH:mm
  • uuuu-MM-dd'T'HH:mm:ss
  • uuuu-MM-dd'T'HH:mm:ss.SSS
  • uuuu-MM-dd'T'HH:mm:ss.SSSSSS
  • uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSS
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!