DATACMNS-1171 - Do not create PersistentEntity for unsupported Kotlin classes.
We now reject unsupported Kotlin classes from the MappingContext by default by not creating persistent entities. Original pull request: #245.
This commit is contained in:
committed by
Oliver Gierke
parent
d9d0d594e5
commit
cc0ab54c38
@@ -471,15 +471,22 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
|
||||
/**
|
||||
* Returns whether a {@link PersistentEntity} instance should be created for the given {@link TypeInformation}. By
|
||||
* default this will reject this for all types considered simple, but it might be necessary to tweak that in case you
|
||||
* have registered custom converters for top level types (which renders them to be considered simple) but still need
|
||||
* meta-information about them.
|
||||
* default this will reject all types considered simple and non-supported Kotlin classes, but it might be necessary to
|
||||
* tweak that in case you have registered custom converters for top level types (which renders them to be considered
|
||||
* simple) but still need meta-information about them.
|
||||
* <p/>
|
||||
*
|
||||
* @param type will never be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
|
||||
return !simpleTypeHolder.isSimpleType(type.getType());
|
||||
|
||||
if (simpleTypeHolder.isSimpleType(type.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !org.springframework.data.util.ReflectionUtils.isKotlinClass(type.getType())
|
||||
|| org.springframework.data.util.ReflectionUtils.isSupportedKotlinClass(type.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class AbstractMappingContextUnitTests {
|
||||
|
||||
@@ -210,6 +211,16 @@ public class AbstractMappingContextUnitTests {
|
||||
assertHasEntityFor(TreeMap.class, context, false);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void shouldCreateEntityForKotlinDataClass() {
|
||||
assertThat(context.getPersistentEntity(SimpleDataClass.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1171
|
||||
public void shouldNotCreateEntityForSyntheticKotlinClass() {
|
||||
assertThat(context.getPersistentEntity(TypeCreatingSyntheticClass.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-695
|
||||
public void persistentPropertyPathTraversesGenericTypesCorrectly() {
|
||||
assertThat(context.getPersistentPropertyPath("field.wrapped.field", Outer.class)).hasSize(3);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
*
|
||||
* http://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.mapping.context
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
data class SimpleDataClass(val firstname: String) {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
*
|
||||
* http://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.mapping.context
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class TypeCreatingSyntheticClass {
|
||||
}
|
||||
|
||||
fun foobar(args: Array<String>) {
|
||||
}
|
||||
Reference in New Issue
Block a user