Skip to content

Commit 6f43390

Browse files
committed
DATAMONGO-1376 - Moved away from SimpleTypeInformationMapper.INSTANCE.
Related tickets: DATACMNS-815.
1 parent ba902e7 commit 6f43390

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapper.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,9 +45,9 @@
4545
public class DefaultMongoTypeMapper extends DefaultTypeMapper<DBObject> implements MongoTypeMapper {
4646

4747
public static final String DEFAULT_TYPE_KEY = "_class";
48-
@SuppressWarnings("rawtypes")//
48+
@SuppressWarnings("rawtypes") //
4949
private static final TypeInformation<List> LIST_TYPE_INFO = ClassTypeInformation.from(List.class);
50-
@SuppressWarnings("rawtypes")//
50+
@SuppressWarnings("rawtypes") //
5151
private static final TypeInformation<Map> MAP_TYPE_INFO = ClassTypeInformation.from(Map.class);
5252

5353
private final TypeAliasAccessor<DBObject> accessor;
@@ -58,20 +58,21 @@ public DefaultMongoTypeMapper() {
5858
}
5959

6060
public DefaultMongoTypeMapper(String typeKey) {
61-
this(typeKey, Arrays.asList(SimpleTypeInformationMapper.INSTANCE));
61+
this(typeKey, Arrays.asList(new SimpleTypeInformationMapper()));
6262
}
6363

6464
public DefaultMongoTypeMapper(String typeKey, MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext) {
65-
this(typeKey, new DBObjectTypeAliasAccessor(typeKey), mappingContext, Arrays
66-
.asList(SimpleTypeInformationMapper.INSTANCE));
65+
this(typeKey, new DBObjectTypeAliasAccessor(typeKey), mappingContext,
66+
Arrays.asList(new SimpleTypeInformationMapper()));
6767
}
6868

6969
public DefaultMongoTypeMapper(String typeKey, List<? extends TypeInformationMapper> mappers) {
7070
this(typeKey, new DBObjectTypeAliasAccessor(typeKey), null, mappers);
7171
}
7272

7373
private DefaultMongoTypeMapper(String typeKey, TypeAliasAccessor<DBObject> accessor,
74-
MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext, List<? extends TypeInformationMapper> mappers) {
74+
MappingContext<? extends PersistentEntity<?, ?>, ?> mappingContext,
75+
List<? extends TypeInformationMapper> mappers) {
7576

7677
super(accessor, mappingContext, mappers);
7778

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DefaultMongoTypeMapperUnitTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,9 +48,9 @@ public class DefaultMongoTypeMapperUnitTests {
4848
@Before
4949
public void setUp() {
5050

51-
configurableTypeInformationMapper = new ConfigurableTypeInformationMapper(Collections.singletonMap(String.class,
52-
"1"));
53-
simpleTypeInformationMapper = SimpleTypeInformationMapper.INSTANCE;
51+
configurableTypeInformationMapper = new ConfigurableTypeInformationMapper(
52+
Collections.singletonMap(String.class, "1"));
53+
simpleTypeInformationMapper = new SimpleTypeInformationMapper();
5454

5555
typeMapper = new DefaultMongoTypeMapper();
5656
}
@@ -81,8 +81,8 @@ public void writesMapKeyForType() {
8181
@Test
8282
public void writesClassNamesForUnmappedValuesIfConfigured() {
8383

84-
typeMapper = new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, Arrays.asList(
85-
configurableTypeInformationMapper, simpleTypeInformationMapper));
84+
typeMapper = new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY,
85+
Arrays.asList(configurableTypeInformationMapper, simpleTypeInformationMapper));
8686

8787
writesTypeToField(new BasicDBObject(), String.class, "1");
8888
writesTypeToField(new BasicDBObject(), Object.class, Object.class.getName());
@@ -101,11 +101,12 @@ public void readsTypeForMapKey() {
101101
@Test
102102
public void readsTypeLoadingClassesForUnmappedTypesIfConfigured() {
103103

104-
typeMapper = new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, Arrays.asList(
105-
configurableTypeInformationMapper, simpleTypeInformationMapper));
104+
typeMapper = new DefaultMongoTypeMapper(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY,
105+
Arrays.asList(configurableTypeInformationMapper, simpleTypeInformationMapper));
106106

107107
readsTypeFromField(new BasicDBObject(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, "1"), String.class);
108-
readsTypeFromField(new BasicDBObject(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, Object.class.getName()), Object.class);
108+
readsTypeFromField(new BasicDBObject(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, Object.class.getName()),
109+
Object.class);
109110
}
110111

111112
/**
@@ -144,7 +145,8 @@ public void doesNotWriteTypeInformationInCaseKeyIsSetToNull() {
144145

145146
@Test
146147
public void readsTypeFromDefaultKeyByDefault() {
147-
readsTypeFromField(new BasicDBObject(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, String.class.getName()), String.class);
148+
readsTypeFromField(new BasicDBObject(DefaultMongoTypeMapper.DEFAULT_TYPE_KEY, String.class.getName()),
149+
String.class);
148150
}
149151

150152
@Test

0 commit comments

Comments
 (0)