DATAMONGO-2174 - Fix InvalidPersistentPropertyPath exception when updating documents.
MetadataBackedField.getPath() now returns null instead throwing an error for fields that are not part of the domain model. This allows adding any field when updating an entity. Original pull request: #633.
This commit is contained in:
committed by
Mark Paluch
parent
9288472fd9
commit
161a983c5d
@@ -982,6 +982,7 @@ public class QueryMapper {
|
||||
* @param pathExpression
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
private PersistentPropertyPath<MongoPersistentProperty> getPath(String pathExpression) {
|
||||
|
||||
try {
|
||||
@@ -1007,7 +1008,7 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
return propertyPath;
|
||||
} catch (PropertyReferenceException e) {
|
||||
} catch (PropertyReferenceException | InvalidPersistentPropertyPath e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.springframework.data.mongodb.core.DocumentTestUtils.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -979,6 +980,15 @@ public class UpdateMapperUnitTests {
|
||||
.doesNotContainKey("$set.concreteInnerList.[0]._class");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2174
|
||||
public void mappingUpdateDocumentWithExplicitFieldNameShouldBePossible() {
|
||||
|
||||
Document mappedUpdate = mapper.getMappedObject(new Document("AValue", "a value"),
|
||||
context.getPersistentEntity(TypeWithFieldNameThatCannotBeDecapitalized.class));
|
||||
|
||||
assertThat(mappedUpdate).isEqualTo(new Document("AValue", "a value"));
|
||||
}
|
||||
|
||||
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
||||
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
|
||||
}
|
||||
@@ -1291,4 +1301,15 @@ public class UpdateMapperUnitTests {
|
||||
String value;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class TypeWithFieldNameThatCannotBeDecapitalized {
|
||||
|
||||
@Id
|
||||
protected String id;
|
||||
|
||||
@Field("AValue")
|
||||
private Long aValue = 0L;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user