Sitelet https://github.com/jasync-sql/jasync-sql/issues/229
Skip to content

BinaryRowEncoder does not support encode java.time.LocalDateTime #229

Description

@ONI-MIKO

environment

jasync-r2dbc-mysql version: 1.1.7

<!-- r2dbc mysql -->
<dependency>
   <groupId>com.github.jasync-sql</groupId>
   <artifactId>jasync-r2dbc-mysql</artifactId>
   <version>1.1.7</version>
</dependency>

insert into database report this error:

Caused by: java.lang.UnsupportedOperationException: An operation is not implemented: couldn't find mapping for class java.time.LocalDateTime
	at com.github.jasync.sql.db.mysql.binary.BinaryRowEncoder.encoderFor(BinaryRowEncoder.kt:100) ~[jasync-mysql-1.1.7.jar:na]
	at com.github.jasync.sql.db.mysql.encoder.PreparedStatementExecuteEncoder.encodeValue(PreparedStatementExecuteEncoder.kt:62) ~[jasync-mysql-1.1.7.jar:na]
	at com.github.jasync.sql.db.mysql.encoder.PreparedStatementExecuteEncoder.encodeValues(PreparedStatementExecuteEncoder.kt:46) ~[jasync-mysql-1.1.7.jar:na]
	at com.github.jasync.sql.db.mysql.encoder.PreparedStatementExecuteEncoder.encode(PreparedStatementExecuteEncoder.kt:27) ~[jasync-mysql-1.1.7.jar:na]
	at com.github.jasync.sql.db.mysql.codec.MySQLOneToOneEncoder.encode(MySQLOneToOneEncoder.kt:67) ~[jasync-mysql-1.1.7.jar:na]
	at com.github.jasync.sql.db.mysql.codec.MySQLOneToOneEncoder.encode(MySQLOneToOneEncoder.kt:23) ~[jasync-mysql-1.1.7.jar:na]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89) ~[netty-codec-4.1.58.Final.jar:4.1.58.Final]
	... 33 common frames omitted

this is my entity example

import java.time.LocalDateTime;

public class MyEntity {
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
}

I saw this part of the code for the BinaryRowEncoder

fun encoderFor(v: Any): BinaryEncoder {
    return this.encoders.getOrElse(v::class.java) {
        return when (v) {
            is CharSequence -> this.stringEncoder
            is java.math.BigInteger -> this.stringEncoder
            is BigDecimal -> this.stringEncoder
            is ReadableDateTime -> DateTimeEncoder
            is ReadableInstant -> ReadableInstantEncoder
            is LocalDateTime -> LocalDateTimeEncoder
            is java.sql.Timestamp -> SQLTimestampEncoder
            is java.sql.Date -> SQLDateEncoder
            is java.util.Calendar -> CalendarEncoder
            is LocalDate -> LocalDateEncoder
            is LocalTime -> LocalTimeEncoder
            is java.sql.Time -> SQLTimeEncoder
            is Duration -> DurationEncoder
            is java.util.Date -> JavaDateEncoder
            is ByteBuffer -> ByteBufferEncoder
            is ByteBuf -> ByteBufEncoder
            else -> XXX("couldn't find mapping for ${v::class.java}")
        }
    }
}

can add support for java.time.LocalDateTime ?

Activity

github-actions commented on Mar 9, 2021

@github-actions

Thank you for reporting an issue. See the wiki for documentation and gitter for questions.

oshai commented on Mar 9, 2021

@oshai
Contributor

Hi, thanks for reporting. Currently the library uses joda time for dates. There was an attempt to replace that in the past but it was never completed, see: #131

The easiest workaround is to use Date/Time object from joda lib.

oshai commented on Mar 9, 2021

@oshai
Contributor

BTW - having support only for writing it to the db is much simpler (the problem is what type to read), so if only that required it might be simpler to implement.

github-actions commented on May 9, 2021

@github-actions

Stale issue message

dragneelfps commented on May 27, 2021

@dragneelfps
Contributor

can we reopen this? This is a much needed feature.

oshai commented on May 30, 2021

@oshai
Contributor

We can reopen this, mostly if you're willing to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions