DATAMONGO-2599 - Eagerly consider enum types as simple types.
MongoSimpleTypes now eagerly checks if a type is a simple one to avoid PersistentEntity registration for ChronoUnit.
This commit is contained in:
@@ -48,6 +48,7 @@ import com.mongodb.client.model.geojson.Polygon;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public abstract class MongoSimpleTypes {
|
||||
|
||||
@@ -109,6 +110,10 @@ public abstract class MongoSimpleTypes {
|
||||
@Override
|
||||
public boolean isSimpleType(Class<?> type) {
|
||||
|
||||
if (type.isEnum()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type.getName().startsWith("java.time")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
@@ -160,6 +161,18 @@ public class MongoMappingContextUnitTests {
|
||||
.withMessageContaining("score").withMessageContaining("Float").withMessageContaining("Double");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2599
|
||||
void shouldNotCreateEntityForEnum() {
|
||||
|
||||
MongoMappingContext context = new MongoMappingContext();
|
||||
|
||||
BasicMongoPersistentEntity<?> entity = context.getRequiredPersistentEntity(ClassWithChronoUnit.class);
|
||||
|
||||
assertThat(entity.getPersistentProperty("unit").isEntity()).isFalse();
|
||||
assertThat(context.hasPersistentEntityFor(ChronoUnit.class)).isFalse();
|
||||
assertThat(context.getPersistentEntity(ChronoUnit.class)).isNull();
|
||||
}
|
||||
|
||||
public class SampleClass {
|
||||
|
||||
Map<String, SampleClass> children;
|
||||
@@ -226,4 +239,9 @@ public class MongoMappingContextUnitTests {
|
||||
|
||||
@TextScore Locale score;
|
||||
}
|
||||
|
||||
class ClassWithChronoUnit {
|
||||
|
||||
ChronoUnit unit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user