diff --git a/pom.xml b/pom.xml index f785c3872d..1025e2bed6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 4.4.0-SNAPSHOT + 4.4.0-4485-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml index a3dc49f892..20dd4a6c8c 100644 --- a/spring-data-mongodb-benchmarks/pom.xml +++ b/spring-data-mongodb-benchmarks/pom.xml @@ -7,7 +7,7 @@ org.springframework.data spring-data-mongodb-parent - 4.4.0-SNAPSHOT + 4.4.0-4485-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index acdc13437d..9e81ba5b3d 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -15,7 +15,7 @@ org.springframework.data spring-data-mongodb-parent - 4.4.0-SNAPSHOT + 4.4.0-4485-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index fafe9c8793..921d97a089 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -13,7 +13,7 @@ org.springframework.data spring-data-mongodb-parent - 4.4.0-SNAPSHOT + 4.4.0-4485-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 67df29623f..0c4d396cd4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -559,7 +559,8 @@ private S populateProperties(ConversionContext context, MongoPersistentEntit MongoDbPropertyValueProvider valueProvider = new MongoDbPropertyValueProvider(contextToUse, documentAccessor, evaluator, spELContext); - Predicate propertyFilter = isIdentifier(entity).or(isConstructorArgument(entity)).negate(); + Predicate propertyFilter = isIdentifier(entity).or(isConstructorArgument(entity)) + .or(Predicates.negate(PersistentProperty::isReadable)).negate(); readProperties(contextToUse, entity, accessor, documentAccessor, valueProvider, evaluator, propertyFilter); return accessor.getBean(); diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/MappingMongoConverterKtUnitTests.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/MappingMongoConverterKtUnitTests.kt new file mode 100644 index 0000000000..0c55b361e9 --- /dev/null +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/MappingMongoConverterKtUnitTests.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2024 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.mongodb.core.convert + +import org.assertj.core.api.Assertions.assertThat +import org.bson.Document +import org.junit.jupiter.api.Test +import org.springframework.data.mongodb.core.mapping.MongoMappingContext + +/** + * Kotlin unit tests for [MappingMongoConverter]. + * + * @author Mark Paluch + */ +class MappingMongoConverterKtUnitTests { + + @Test // GH-4485 + fun shouldIgnoreNonReadableProperties() { + + val document = Document.parse("{_id: 'baz', type: 'SOME_VALUE'}") + val converter = + MappingMongoConverter(NoOpDbRefResolver.INSTANCE, MongoMappingContext()) + + val tx = converter.read(SpecialTransaction::class.java, document) + + assertThat(tx.id).isEqualTo("baz") + assertThat(tx.type).isEqualTo("SOME_DEFAULT_VALUE") + } +} diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/SpecialTransaction.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/SpecialTransaction.kt new file mode 100644 index 0000000000..14ef476a58 --- /dev/null +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/convert/SpecialTransaction.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2024 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.mongodb.core.convert + +abstract class SomeTransaction() { + + abstract val id: String + abstract val type: String +} + +data class SpecialTransaction(override val id: String) : SomeTransaction() { + override val type: String = "SOME_DEFAULT_VALUE" +}