Skip to content

DATAMONGO-2101 - Fix DBObject to GeoJson conversion. #614

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>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-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>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-SNAPSHOT</version>
</dependency>

<!-- reactive -->
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 @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-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>2.0.11.BUILD-SNAPSHOT</version>
<version>2.0.11.DATAMONGO-2101-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent;
import org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent;
import org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent;
import org.springframework.data.mongodb.util.BsonUtils;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -207,6 +208,8 @@ private <S extends Object> S read(TypeInformation<S> type, @Nullable Bson bson,

if (conversions.hasCustomReadTarget(bson.getClass(), rawType)) {
return conversionService.convert(bson, rawType);
} else if (bson instanceof DBObject && conversions.hasCustomReadTarget(Document.class, rawType)) {
return conversionService.convert(new Document(BsonUtils.asMap(bson)), rawType);
}

if (DBObject.class.isAssignableFrom(rawType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@
*/
package org.springframework.data.mongodb.repository;

import lombok.Getter;
import lombok.Setter;

import org.springframework.data.mongodb.core.geo.GeoJson;

import com.querydsl.core.annotations.QueryEmbeddable;

/**
* @author Oliver Gierke
* @author Christoph Strobl
*/
@QueryEmbeddable
@Getter
@Setter
public class Address {

private String street;
private String zipCode;
private String city;

private GeoJson location;

protected Address() {

}
Expand All @@ -41,46 +51,4 @@ public Address(String street, String zipcode, String city) {
this.zipCode = zipcode;
this.city = city;
}

/**
* @return the street
*/
public String getStreet() {
return street;
}

/**
* @param street the street to set
*/
public void setStreet(String street) {
this.street = street;
}

/**
* @return the zipCode
*/
public String getZipCode() {
return zipCode;
}

/**
* @param zipCode the zipCode to set
*/
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}

/**
* @return the city
*/
public String getCity() {
return city;
}

/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.repository.Address;
import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.mongodb.repository.QPerson;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
Expand Down Expand Up @@ -99,4 +101,21 @@ public void findOneWithPredicateReturnsOptionalEmptyWhenNoDataFound() {
public void findOneWithPredicateThrowsExceptionForNonUniqueResults() {
repository.findOne(person.firstname.contains("e"));
}

@Test // DATAMONGO-2101
public void readEntityWithGeoJsonValue() {

Address adr1 = new Address("Hauptplatz", "4020", "Linz");
adr1.setLocation(new GeoJsonPoint(48.3063548, 14.2851337));

Person person1 = new Person("Max", "The Mighty");
person1.setAddress(adr1);

operations.save(person1);

List<Person> result = new SpringDataMongodbQuery<>(operations, Person.class).where(person.firstname.eq("Max"))
.fetch();

assertThat(result).containsExactly(person1);
}
}