Skip to content

Commit eda8200

Browse files
committed
DATAMONGO-523 - Added test case to verify type alias detection.
1 parent b078ea9 commit eda8200

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.core.convert.converter.Converter;
5050
import org.springframework.data.annotation.Id;
5151
import org.springframework.data.annotation.PersistenceConstructor;
52+
import org.springframework.data.annotation.TypeAlias;
5253
import org.springframework.data.mapping.PropertyPath;
5354
import org.springframework.data.mapping.model.MappingException;
5455
import org.springframework.data.mapping.model.MappingInstantiationException;
@@ -1292,6 +1293,23 @@ public void eagerlyReturnsDBRefObjectIfTargetAlreadyIsOne() {
12921293
assertThat(converter.createDBRef(dbRef, annotation), is(dbRef));
12931294
}
12941295

1296+
/**
1297+
* @see DATAMONGO-523
1298+
*/
1299+
@Test
1300+
public void considersTypeAliasAnnotation() {
1301+
1302+
Aliased aliased = new Aliased();
1303+
aliased.name = "foo";
1304+
1305+
DBObject result = new BasicDBObject();
1306+
converter.write(aliased, result);
1307+
1308+
Object type = result.get("_class");
1309+
assertThat(type, is(notNullValue()));
1310+
assertThat(type.toString(), is("_"));
1311+
}
1312+
12951313
static class GenericType<T> {
12961314
T content;
12971315
}
@@ -1475,6 +1493,11 @@ public TypWithCollectionConstructor(List<Attribute> attributes) {
14751493
}
14761494
}
14771495

1496+
@TypeAlias("_")
1497+
static class Aliased {
1498+
String name;
1499+
}
1500+
14781501
private class LocalDateToDateConverter implements Converter<LocalDate, Date> {
14791502

14801503
public Date convert(LocalDate source) {

0 commit comments

Comments
 (0)