Comments (5)
R2dbcCustomConversions
keeps track of read and write targets. When registering a converter, we determine the custom read or write target. If that is set, then we register the converter in Spring's ConversionService and use the conversion service to perform the actual conversion.
Spring's ConversionService
comes already with a converter (StringToEnumConverterFactory
) that matches Enum<T>
as target type. Because of type erasure, the T
from EmptyStringToEnumReadingConverter<T extends Enum<T>>
is being flattened down to Enum
and therefore, the conversion service now has two converters. Spring's ConversionService checks the raw type for your converter and since the raw type is Enum
and not Debt.DebtSource
, the custom converter isn't used.
Instead, StringToEnum
is provided by the StringToEnumConverterFactory
that is a ConverterFactory
and it creates an instance for string to enum conversion with an exact type match.
Let me know whether this helps.
from spring-data-r2dbc.
Enum conversion works as designed. null
values in the column map to null
values in the domain model. Anything else is being looked up through Enum.valueOf(…)
. Translating empty string values to null
is a rule specific to your domain and not something that applies broadly.
As this is a rather specific issue, please configure a custom conversions bean for your application.
from spring-data-r2dbc.
I don't know if you get my point here.
When I create the custom conversion bean it is not used. The org.springframework.core.convert.support.StringToEnumConverterFactory.StringToEnum
is used instead and it deals with empty strings.
The question is why the Spring StringToEnum
is used only if R2dbcCustomConversions
are declared (not empty), and why my custom bean is not used.
from spring-data-r2dbc.
@mp911de - I still think it's a bug or a inconsistent behavior, do you disagree?
from spring-data-r2dbc.
After the explanation, I got the point of why my converter is not used.
What I didn't understand was why the Spring ConversionService
and StringToEnumConverterFactory
were not used without the registration of the R2dbcCustomConversions
bean. I thought that spring
and spring-data-r2dbc
would treat the data equally. Your answer covers that a little.
It is also a little bit unclear that one day we will throw an error on an empty string, and on the next day if you register the custom converter for literally anything, your enums will be converted without any error.
from spring-data-r2dbc.
Related Issues (20)
- Release 1.5.17 (2021.2.17)
- Model entity need to add custom Encryption on insert/update and decrypt on read HOT 4
- Upgrade to Maven Wrapper 3.9.5
- Release 1.5.18 (2021.2.18)
- NativeParameterUtils doesn't support collection with nullable values HOT 7
- Issue with @Transient HOT 3
- Manage transaction name when use @Transactional annotatnion HOT 1
- Transaction rollback does not work when using jOOQ HOT 1
- Custom converter in R2dbcEntityOperations breaks nested mappings
- Caused by: io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42883] operator does not exist: traffic_type = character varying
- ConditionalGenericConverter is not properly handled by Spring Data R2DBC HOT 1
- Save entity with custom UUID identifier HOT 2
- `bindProperties` throws error when entities contain enum fields HOT 1
- IN clause not working HOT 4
- `findAllByxxx` incorrectly returns a single object instead of an Iterable. HOT 1
- Unexpected behaviour when using repository saveAll() in WebFilter with response body HOT 3
- java.lang.IllegalStateException: Required property not found for class HOT 3
- Bug: different behaviour between save(save(x)), and save(find(save(x))) HOT 3
- Occurs ConverterNotFoundException [java.nio.HeapByteBuffer] to type [java.lang.Boolean] on boot 3.3.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-r2dbc.