Skip to content

DocumentReference should consider Reference annotations #3852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3851-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3851-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3851-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.3.0-GH-3851-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ protected void writePropertyInternal(@Nullable Object obj, DocumentAccessor acce
return;
}

if (prop.isAssociation()) {
if (prop.isAssociation() && prop.isAnnotationPresent(Reference.class)) {

accessor.put(prop, new DocumentPointerFactory(conversionService, mappingContext)
.computePointer(mappingContext, prop, obj, valueType.getType()).getPointer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,26 @@ void readsMapThatDoesNotComeAsDocument() {
ClassWithMapProperty target = converter.read(ClassWithMapProperty.class, source);

assertThat(target.mapOfObjects).containsEntry("simple",1);
}

@Test // GH-3851
void associationMappingShouldFallBackToDefaultIfNoAtReferenceAnnotationPresent/* as done via jmolecules */() {

UUID id = UUID.randomUUID();
Person sourceValue = new Person();
sourceValue.id = id.toString();

DocumentAccessor accessor = new DocumentAccessor(new org.bson.Document());
MongoPersistentProperty persistentProperty = mock(MongoPersistentProperty.class);
when(persistentProperty.isAssociation()).thenReturn(true);
when(persistentProperty.getFieldName()).thenReturn("pName");
doReturn(ClassTypeInformation.from(Person.class)).when(persistentProperty).getTypeInformation();
doReturn(Person.class).when(persistentProperty).getType();
doReturn(Person.class).when(persistentProperty).getRawType();

converter.writePropertyInternal(sourceValue, accessor, persistentProperty);

assertThat(accessor.getDocument()).isEqualTo(new org.bson.Document("pName", new org.bson.Document("_id", id.toString())));
}

static class GenericType<T> {
Expand Down