Closed ilangranet closed 11 months ago
This should work and I'll fix it. In the meantime, you might try a JsonArray instead of a List
This should work and I'll fix it. In the meantime, you might try a JsonArray instead of a List
I tried and get the same issue: java.lang.IllegalArgumentException: Attribute of type com.couchbase.client.java.json.JsonArray cannot be stored and must be converted.
I haven't investigated this yet, but this is more likely the issue. How is Object supposed to be serialized? Deserialized? What constructor should be used?
@Field
private Object myObject;
@mikereiche this is a regression in v5. Could you make it work like it used to be in v4 ?
The issue is that conversion.isSimpleType() considers Object to be a simple type, while the
if (!conversions.isSimpleType(prop.getType())) {
writePropertyInternal(propertyObj, target, prop, accessor);
} else {
writeSimpleInternal(prop, accessor, target, prop.getFieldName());
}
While verifyValue (called from target.put() called from writeSimpleInternal()) does not consider it to be a simpletype.
CouchbaseDocument
private void verifyValueType(final Object value) {
if (value == null) {
return;
}
final Class<?> clazz = value.getClass();
if (CouchbaseSimpleTypes.DOCUMENT_TYPES.isSimpleType(clazz)) {
return;
}
throw new IllegalArgumentException(
"Attribute of type " + clazz.getCanonicalName() + " cannot be stored and must be converted.");
}
@roman-sinyakov
this is a regression in v5. Could you make it work like it used to be in v4 ?
I can make the serialization (save) work. But it appears that the deserialization (findById etc), did not work in v4 and won't work in v5 without other changes.
The breaking change is in MappingCouchbaseConverter.java. old line 579 vs new line 616 - propertyObj.getClass() (the object) vs prop.getType() (the field on the class)
@roman-sinyakov @ilangranet - are you ok with saving working, but reading (still) not working?
@roman-sinyakov @ilangranet - are you ok with saving working, but reading (still) not working?
with spring data 4.x, save and read were working. we still need both.
I thought I tried reading with 4.x and it didn't work. I'll look again
I tried with spring boot 2.7.13, which brings
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>4.4.13</version>
<scope>compile</scope>
</dependency>
it worked both save and read.
Thanks. I'll investigate on Monday.
@ilangranet - I can't get the read to work in 4.4.x or in anything else. Since the field type is Object, it doesn't have a componentType (line 766). So when readCollection() is called at line 776 with componentType==null, it throws an exception because it does not accept a null targetType.
@mikereiche Hi, I've just run across to this issue on starter-data-couchbase 3.2.2 with data-couchbase 5.2.2. I see that this has been merged to 5.2.x and main branch already. When will it be shipped, any plans? Any workarounds you'd suggest until that time rather than rolling back? Thanks.
Tomorrow. https://calendar.spring.io/
Hi,
I am using Spring boot: 3.2.0 with Spring data Couchbase: 5.2.0
I have an entity defined with a field of type Object (this field can be everything (String or List...)):
while trying to save it using this:
personRepository.save(new Person("1", "Alice", 25, Collections.singletonList("my issue")));
It failed on java.lang.IllegalArgumentException: Attribute of type java.util.Collections.SingletonList cannot be stored and must be converted.
it was working with previous version: Spring boot: 2.7.13, Spring data Couchbase: 4.4.13. demo.zip
Find attached the project where it failed: to reproduce, run PersonRepositoryTest
Any suggestion?
Thank you