Fix regression - unable to store and read properties of type Object. (#1883)
Closes #1875.
This commit is contained in:
committed by
mikereiche
parent
1db7fb95c0
commit
424736fc19
@@ -614,7 +614,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
|
||||
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 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<MyPerson, String>, DynamicProxyable<PersonRepository> {
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.lang.reflect.Method;
|
||||
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.EITurbulenceCategory;
|
||||
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 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
}
|
||||
}
|
||||
|
||||
@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<MyPerson> 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");
|
||||
|
||||
Reference in New Issue
Block a user