-
Notifications
You must be signed in to change notification settings - Fork 192
Spring boot: 3.4.3, Spring data Couchbase: 5.4.3 java.lang.IllegalArgumentException: Attribute of type java.util.Collections.SingletonList cannot be stored and must be converted. #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
have created PR #2042 |
Note to self: Need lombok 1.18.30 or later to use with JDK 21 There is a behavior change between 5.1.5 and 5.1.6. The only change between 5.1.5 and 5.1.6 is 2281ba2 |
@umeshmishra099 - the issue is that the mapping converter finds the JsonValue annotated method values() in LocalizedStrings - which returns a list. And it does not expect a non-Collection-like property to map to a collection. If the JsonValue annotation is removed - it seems to work. in 3.2, CachingPropertyValueConverterFactory, the delegate holds a SimpleConverterPropertyFactory
The CouchbasePropertyValueConverter finds the @JsonValue annotated method to use for write conversion - that method returns a List which fails validation. in 3.2, the delegate does not find any converter, thus the calling code in AbstractCouchbaseConverter.convertForWriteIfNeeded() continues to look for a converter, and finds the Local
|
@mikereiche - LocalizedStrings is something thirdparty we are using. can you suggest any other way to fix it |
This is the commit that gives the different behavior. 2281ba2 Before that change, creating a MappingCouchbaseConverter( mappingContext ) does not have the converter for annotations (such as JsonValue), and therefore the LocalizedStringConverter was being used. And it was working because the LocalizedStringConverter returns a CouchbaseList, while the @JsonValue method of LocalizedStrings returns an Array. I don't know if/where it's possible to specify a priority when there are multiple options for conversions. Or if it's possible to recursively apply converters (the Array returned from the @JsonValue method would be converted to a CouchbaseList if ran through the converter) After CustomMappingCouchbaseConverter is created, only CommonCustomConverterUtils.getCommonCustomConverters() are added.
The mapping converter should be created as the original in AbstractCouchbaseConfiguration, which takes the conversions as an argument.
Additional converters should be added by overriding AbstractCouchbaseConfiguration.additionalConverters(List converters). The type is Object to take either converters or converter factories.
// use this constructor notes to self: reformat line 'converterConfigurationAdapter.registerConverters(newConverters);' and this is the annotation converter factory new CouchbasePropertyValueConverterFactory(null, AbstractCouchbaseConfiguration.annotationToConverterMap(), om)); |
What is the purpose of the read() method in CustomMappingCouchbaseConverter ? Could you not just use the provided mapper with the additional converters? |
To fix: Use these three methods in your CommonCouchbaseConfig...
and change the constructor of your CustomMappingCouchbaseConverter to use the supplied conversions, instead of the default ones from CouchbaseCustomConversions.
|
@mikereiche it working fine after doing all changes you suggested. |
Thanks for your patience. |
Hi
We are upgrading from spring boot 3.2.4 to 3.4.3 We are getting issue below issue.
java.lang.IllegalArgumentException: Attribute of type java.util.Collections.SingletonList cannot be stored and must be converted.
it was working Spring boot: [3.2.4]
demo_3_2.zip
it fails with Spring boot: [3.4.3]
demo_3_4.zip
Step to test
Run spring boot application
Run this curl
curl --location --request POST 'http://localhost:8080/api/testpojo/create'
--header 'Content-Type: application/json'
--data-raw '{
"field1": "value55",
"field2": [{
"locale": "en-US",
"value": "test data11"
}],
"field3": "value3",
"field4": "value4",
"field5": "value5"
}'
it fails for spring boot 3.4.3 with error java.lang.IllegalArgumentException: Attribute of type java.util.ArrayList cannot be stored and must be converted.
The text was updated successfully, but these errors were encountered: