DATAMONGO-1772 - Fix UpdateMapper type key rendering for abstract list elements contained in concrete typed ones.
Original pull request: #497.
This commit is contained in:
committed by
Mark Paluch
parent
f71b38b731
commit
166304849a
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.convert;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
@@ -161,6 +162,10 @@ public class UpdateMapper extends QueryMapper {
|
||||
return info;
|
||||
}
|
||||
|
||||
if (source instanceof Collection) {
|
||||
return NESTED_DOCUMENT;
|
||||
}
|
||||
|
||||
if (!type.equals(source.getClass())) {
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -901,6 +901,34 @@ public class UpdateMapperUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1772
|
||||
public void mappingShouldAddTypeKeyInListOfInterfaceTypeContainedInConcreteObjectCorrectly() {
|
||||
|
||||
ConcreteInner inner = new ConcreteInner();
|
||||
inner.interfaceTypeList = Collections.<SomeInterfaceType> singletonList(new SomeInterfaceImpl());
|
||||
List<ConcreteInner> list = Collections.singletonList(inner);
|
||||
|
||||
DBObject mappedUpdate = mapper.getMappedObject(new Update().set("concreteInnerList", list).getUpdateObject(),
|
||||
context.getPersistentEntity(Outer.class));
|
||||
|
||||
assertThat(mappedUpdate, isBsonObject().containing("$set.concreteInnerList.[0].interfaceTypeList.[0]._class")
|
||||
.notContaining("$set.concreteInnerList.[0]._class"));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1772
|
||||
public void mappingShouldAddTypeKeyInListOfAbstractTypeContainedInConcreteObjectCorrectly() {
|
||||
|
||||
ConcreteInner inner = new ConcreteInner();
|
||||
inner.abstractTypeList = Collections.<SomeAbstractType> singletonList(new SomeInterfaceImpl());
|
||||
List<ConcreteInner> list = Collections.singletonList(inner);
|
||||
|
||||
DBObject mappedUpdate = mapper.getMappedObject(new Update().set("concreteInnerList", list).getUpdateObject(),
|
||||
context.getPersistentEntity(Outer.class));
|
||||
|
||||
assertThat(mappedUpdate, isBsonObject().containing("$set.concreteInnerList.[0].abstractTypeList.[0]._class")
|
||||
.notContaining("$set.concreteInnerList.[0]._class"));
|
||||
}
|
||||
|
||||
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
||||
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
|
||||
}
|
||||
@@ -1187,4 +1215,26 @@ public class UpdateMapperUnitTests {
|
||||
Integer intValue;
|
||||
int primIntValue;
|
||||
}
|
||||
|
||||
static class Outer {
|
||||
List<ConcreteInner> concreteInnerList;
|
||||
}
|
||||
|
||||
static class ConcreteInner {
|
||||
List<SomeInterfaceType> interfaceTypeList;
|
||||
List<SomeAbstractType> abstractTypeList;
|
||||
}
|
||||
|
||||
interface SomeInterfaceType {
|
||||
|
||||
}
|
||||
|
||||
static abstract class SomeAbstractType {
|
||||
|
||||
}
|
||||
|
||||
static class SomeInterfaceImpl extends SomeAbstractType implements SomeInterfaceType {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user