Add Point reading from coordinate arrays#5194
Add Point reading from coordinate arrays#5194DragonFSKY wants to merge 1 commit intospring-projects:mainfrom
Conversation
Closes spring-projects#4997 Signed-off-by: dragonfsky <dragonfsky@gmail.com>
|
Thank you @DragonFSKY for providing the PR. Since we already released an RC for the current release train we might consider your contribution for the next iteration. Until we have time to do a full review of the proposed changes I'd like to leave a comment already that I think needs to be addressed. Currently it is not possible to auto convert I could think of something like the following (which is currently not supported right now) to prevent this from happening. @Field(targetType = FieldType.ARRAY)
Point coordinates;Please, the above is just from a quick glance and should not be taken as implementation advice. Let's discuss things before spending more time changing the PR. |
|
Sorry, my initial thinking was incomplete here. I focused on the read side first and did not think through the read/write storage shape carefully enough. Looking at the current upstream mapping code, My current thought is that array-backed class Location {
@Field(targetType = FieldType.ARRAY)
Point coordinates;
}This way, an explicitly array-backed property could preserve the array representation: { "coordinates": [ -73.99171, 40.738868 ] }while existing { "coordinates": { "x": -73.99171, "y": 40.738868 } }Does that sound like a reasonable direction? If you see a better approach, please feel free to point me in that direction. |
Closes #4997
This PR adds a reading converter that maps coordinate arrays such as
[-73.99171, 40.738868]toPoint.The existing document-based
Pointmapping remains unchanged. Tests cover the direct converter and theMappingMongoConverterpath for a domainPointproperty.Tests:
./mvnw -s settings.xml -pl spring-data-mongodb clean test '-Dtest=GeoConvertersUnitTests,MappingMongoConverterUnitTests#shouldReadEntityWithGeoPointFromArrayCoordinates+convertsListToBasicDBListAndRetainsTypeInformationForComplexObjects+convertsListToBasicDBListWithoutTypeInformationForSimpleTypes'Checklist: