在 tornadofx 中使用 localdatetime 和 rest springboot

using localdatetime in tornadofx with rest springboot

我开发了一个以 springboot rest 服务作为后端的 tornadofx 应用程序
全部使用科特林语言

问题是 tornadofx seNd LocalDateTime as Int 这会导致 springboot 服务器出现此错误

2018-01-31 18:33:31.296  WARN 11473 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected token (VALUE_NUMBER_INT), expected VALUE_STRING: Expected array or string.; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (VALUE_NUMBER_INT), expected VALUE_STRING: Expected array or string.
 at [Source: (PushbackInputStream); line: 1, column: 16] (through reference chain: andalous.torndadoserver.financial.dailymove.newDailyMove["date"])

我加springboot解决不了

<dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.9.1</version>
    </dependency>

并在 application.properties

中使用它
spring.jackson.serialization.write_dates_as_timestamps=false

您可以随意序列化 json 数据。你可以做 json.add("key", someLocalDataTimeValueConvertedToWhateverFormatYouWant) 而不是 json.add("key", someLocalDateTimeValue)。您甚至可以添加一个扩展功能,使其更易于使用。

就是说,对于如何在内置的 JsonBuilder 中存储 LocalDateTime,想出一个可配置的选项应该很容易。欢迎 PR :)

这与 tornadofx 完美结合

override fun toJSON(json: JsonBuilder) {
    with(json){
        add("date",date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
    }
}

override fun updateModel(json: JsonObject) {
    with(json){
        date= LocalDateTime.parse(string("date"),DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
    }
}