eclipse-vertx / vertx-sql-client

High performance reactive SQL Client written in Java
Apache License 2.0
877 stars 195 forks source link

[SqlTemaplte] Reproducer java localDateTime issue #1406

Closed pjgg closed 5 months ago

pjgg commented 5 months ago

Do not merge, it is just a reproducer.

Based on the documentation If I need to work with Java LocalDateTime the only thing that I should configure is the ObjectMapper (by adding this "JavaTimeModule" module). However, I am reaching the following error:

io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[1] with class = [io.vertx.core.json.JsonArray] and value = [[2017,5,14,19,35,58,237666000]] can not be coerced to the expected class = [java.time.LocalDateTime] for encoding.

This is because the java.time.LocalDateTime is mapped as an Array as is Documented on the source. If I change the ObjectMapper config to:

mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

then the error is the following one:

Insert failed: Parameter at position[1] with class = [java.lang.String] and value = [2017-05-14T19:35:58.237666] can not be coerced to the expected class = [java.time.LocalDateTime] for encoding.

That looks like slightly better but is not good enough.

Please find a reproducer on the following "PR".

My question is, do you think this is an issue, or there is a way to config the object mapper and make it work?

tsegismont commented 5 months ago

You need to give Postgres a hint that the value is submitted as a string. For this, you can change the SQL to:

"INSERT INTO revokedkeys (keyhash, valid_until) VALUES (#{keyhash}, to_timestamp(#{valid_until}, 'YYYY-MM-DDTHH:MI:SS.US')::TIMESTAMP WITHOUT TIME ZONE)"