diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index 0a34ce93b..a3c5b1ee9 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -614,7 +614,7 @@ public void doWithPersistentProperty(final CouchbasePersistentProperty prop) { return; } - if (!conversions.isSimpleType(prop.getType())) { + if (!conversions.isSimpleType(propertyObj.getClass())) { writePropertyInternal(propertyObj, target, prop, accessor); } else { writeSimpleInternal(prop, accessor, target, prop.getFieldName()); @@ -813,7 +813,7 @@ private Object readCollection(final TypeInformation targetType, final Couchba if (dbObjItem instanceof CouchbaseDocument) { items.add(read(componentType, (CouchbaseDocument) dbObjItem, parent)); } else if (dbObjItem instanceof CouchbaseList) { - items.add(readCollection(componentType, (CouchbaseList) dbObjItem, parent)); + items.add(readCollection(componentType != null ? componentType :TypeInformation.of(dbObjItem.getClass()), (CouchbaseList) dbObjItem, parent)); } else { items.add(getPotentiallyConvertedSimpleRead(dbObjItem, rawComponentType)); } diff --git a/src/test/java/org/springframework/data/couchbase/domain/MyPerson.java b/src/test/java/org/springframework/data/couchbase/domain/MyPerson.java new file mode 100644 index 000000000..460b79bb6 --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/domain/MyPerson.java @@ -0,0 +1,25 @@ +package org.springframework.data.couchbase.domain; + +import jakarta.validation.constraints.NotNull; +import org.springframework.data.annotation.Id; +import org.springframework.data.couchbase.core.mapping.Field; + +public class MyPerson { + @NotNull + @Id + public String id; + + @Field + public Object myObject; + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("MyPerson:{"); + sb.append("id:"); + sb.append(id); + sb.append(", myObject:"); + sb.append(myObject); + sb.append("}"); + return sb.toString(); + } +} diff --git a/src/test/java/org/springframework/data/couchbase/domain/MyPersonRepository.java b/src/test/java/org/springframework/data/couchbase/domain/MyPersonRepository.java new file mode 100644 index 000000000..2de97d3de --- /dev/null +++ b/src/test/java/org/springframework/data/couchbase/domain/MyPersonRepository.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2023 the original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.couchbase.domain; + +import java.util.List; +import java.util.UUID; + +import org.springframework.data.couchbase.repository.CouchbaseRepository; +import org.springframework.data.couchbase.repository.DynamicProxyable; +import org.springframework.data.couchbase.repository.Query; +import org.springframework.data.couchbase.repository.ScanConsistency; +import org.springframework.data.repository.query.Param; + +import com.couchbase.client.java.query.QueryScanConsistency; + +/** + * @author Michael Reiche + */ +public interface MyPersonRepository extends CouchbaseRepository, DynamicProxyable { + +} + diff --git a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java index c86acdaab..5e365a427 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java @@ -37,6 +37,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -79,6 +80,8 @@ import org.springframework.data.couchbase.domain.EJsonCreatorTurbulenceCategory; import org.springframework.data.couchbase.domain.ETurbulenceCategory; import org.springframework.data.couchbase.domain.Iata; +import org.springframework.data.couchbase.domain.MyPerson; +import org.springframework.data.couchbase.domain.MyPersonRepository; import org.springframework.data.couchbase.domain.NaiveAuditorAware; import org.springframework.data.couchbase.domain.Person; import org.springframework.data.couchbase.domain.PersonRepository; @@ -147,6 +150,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr @Autowired UserSubmissionRepository userSubmissionRepository; + @Autowired MyPersonRepository myPersonRepository; + + @Autowired CouchbaseTemplate couchbaseTemplate; String scopeName = "_default"; @@ -178,6 +184,22 @@ void shouldSaveAndFindAll() { } } + @Test + void findMyPerson() { + MyPerson vie = null; + try { + vie = new MyPerson(); + vie.id = "123"; UUID.randomUUID().toString(); + vie.myObject = Collections.singletonList("a"); + MyPerson p = myPersonRepository.save(vie); + System.err.println(p); + Optional r = myPersonRepository.findById( p.id); + System.err.println(r.get()); + } finally { + try { myPersonRepository.delete(vie); } catch (DataRetrievalFailureException dnfe){} + } + } + @Test void shouldNotSave() { Airport vie = new Airport("airports::vie", "vie", "low4");