Skip to content

Fix regression in saving and reading Object type properties #1883

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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> {

}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -147,6 +150,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr

@Autowired UserSubmissionRepository userSubmissionRepository;

@Autowired MyPersonRepository myPersonRepository;


@Autowired CouchbaseTemplate couchbaseTemplate;

String scopeName = "_default";
Expand Down Expand Up @@ -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<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");
Expand Down