spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

The GeoJsonModule deserialize creates an invalid GeoJsonMultiPolygon

Open boundaries-io opened this issue 2 years ago • 5 comments

The GeoJson deseralizer creates an invalid GeoJsonMultiPolygon that contain holes.

For example, while using a valid GeoJson MultiPolygon: Dallas, Texas GeoJson image

invoking the method

	ObjectMapper mapper = new ObjectMapper();
	mapper.registerModule(GeoJsonModule.serializers());
	mapper.registerModule(GeoJsonModule.deserializers());

 	String dallas = FileUtils.readFileToString(new File("src/test/resources/raw_dallas.geojson"));
	GeoJsonMultiPolygon geoJsonMultiPolygon =  mapper.readValue(dallas, GeoJsonMultiPolygon.class);		 
 	String json =  getObjectMapper().writeValueAsString(geoJsonMultiPolygon);	
	Assert.assertEquals(dallas,json);//fails 	

The JSON is incorrect, the 'holes' that make up the original Multipolygon are being created incorrectly. Invalid Dallas, Texas GeoJson image

-Jeryl Cook

boundaries-io avatar Dec 10 '23 18:12 boundaries-io

Thank you for reporting. It would be great if you have the time to help us work on this issue by providing a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

christophstrobl avatar Dec 11 '23 06:12 christophstrobl

Ok, I will create today

boundaries-io avatar Dec 12 '23 12:12 boundaries-io

created a project with the failed test case: https://github.com/boundaries-io/spring-data-mongodb-4586

boundaries-io avatar Dec 14 '23 02:12 boundaries-io

thank you for the reproducer, any chance to reduce the amount of json data to reproduce the issue? Something that does not necessarily hold hundreds of points but rather a minimal amount to show what's wrong.

christophstrobl avatar Dec 14 '23 07:12 christophstrobl

Hi, The original geoJson is valid and comforms to the GeoJson Spec.( you can test via geojsonlint, or the JTS library, etc.)

I've added another unit test that uses a working Geojson serializer/deserializer from A Working GeoJson Serializer library

boundaries-io avatar Dec 16 '23 04:12 boundaries-io