Unable to register EnumCodec via Spring Boot R2DBC auto-config

105 views Asked by At

I'm using

  1. spring-boot-starter-data-r2dbc 3.1.4
  2. r2dbc-postgresql 1.0.2.RELEASE

I've

  1. created TYPE MY_ENUM AS ENUM
  2. created MyEnumConverter extends org.springframework.data.r2dbc.convert.EnumWriteSupport<MyEnum> as a @WritingConverter and registerd it with org.springframework.data.r2dbc.convert.R2dbcCustomConversions
  3. Explicitly mapped private MyEnum myEnum into the 'entity mapping'
  4. persisted a freshly created entity via org.springframework.data.repository.reactive.ReactiveCrudRepository#save

And got the following error

reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: Cannot encode parameter of type MyEnum
Caused by: java.lang.IllegalArgumentException: Cannot encode parameter of type MyEnum
    at io.r2dbc.postgresql.codec.DefaultCodecs.encodeParameterValue(DefaultCodecs.java:290) ~[r2dbc-postgresql-1.0.2.RELEASE.jar:1.0.2.RELEASE]
    at io.r2dbc.postgresql.codec.DefaultCodecs.encode(DefaultCodecs.java:264) ~[r2dbc-postgresql-1.0.2.RELEASE.jar:1.0.2.RELEASE]
    at io.r2dbc.postgresql.PostgresqlStatement.bind(PostgresqlStatement.java:108) ~[r2dbc-postgresql-1.0.2.RELEASE.jar:1.0.2.RELEASE]
    at io.r2dbc.postgresql.PostgresqlStatement.bind(PostgresqlStatement.java:59) ~[r2dbc-postgresql-1.0.2.RELEASE.jar:1.0.2.RELEASE]
    ...

The configuration to R2DBC was done entirely by Spring Boot Auto Config and I do not want to move away from that. Specifically org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryConfigurations.PoolConfiguration.PooledConnectionFactoryConfiguration#connectionFactory

I want to keep the auto-config, but it does not expose any entry to register an EnumCodec instance, as far as my whole-day-research goes, I debugged the io.r2dbc.postgresql.PostgresqlStatement at runtime and it was indeed using default Codecs.

Could I please get any help, thank you in advance.

0

There are 0 answers