Browse Source

DATAMONGO-1772 - Fix UpdateMapper type key rendering for abstract list elements contained in concrete typed ones.

Original pull request: #497.
pull/499/head
Christoph Strobl 8 years ago committed by Mark Paluch
parent
commit
166304849a
  1. 7
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/UpdateMapper.java
  2. 50
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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;
}

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

@ -901,6 +901,34 @@ public class UpdateMapperUnitTests { @@ -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 { @@ -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 {
}
}

Loading…
Cancel
Save