Closed thorsten-k closed 10 years ago
Due to the fact that the example is not a valid LinearRing as it is not closed, the following test does not work in JtsAdapterFactoryTest:
@Test
public void testBug15() {
Gson gsonGeometry = new GsonBuilder().registerTypeAdapterFactory(new GeometryAdapterFactory()).registerTypeAdapterFactory(new JtsAdapterFactory()).create();
String json = "{ \"type\": \"MultiPolygon\", \"coordinates\": [ [ [ [ 15.0, 20.0 ],[ 16.0, 21.0 ] ] ], [ [ [ 11.0, 24.4 ], [ 11.0, 18.6 ] ] ] ] }";
System.out.println(json);
MultiPolygon jMultiPolygon = gsonGeometry.fromJson(json, MultiPolygon.class);
// now really check the result
String parsedJson = this.toTest.toJson(jMultiPolygon, MultiPolygon.class);
// as we can't compare the input JSON string due to blanks and ordering, so compare it with the generated string
String expectedJson = "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[15.0,20.0],[16.0,21.0]]],[[[11.0,24.4],[11.0,18.6]]]]}"; //$NON-NLS-1$
assertThat(parsedJson, equalTo(expectedJson));
}
To my surprise this did work in GeometryAdapterFactoryTest:
@Test
public void testBug15() {
Gson gsonGeometry = new GsonBuilder().registerTypeAdapterFactory(new GeometryAdapterFactory()).create();
String json = "{ \"type\": \"MultiPolygon\", \"coordinates\": [ [ [ [ 15.0, 20.0 ],[ 16.0, 21.0 ] ] ], [ [ [ 11.0, 24.4 ], [ 11.0, 18.6 ] ] ] ] }";
MultiPolygon jMultiPolygon = gsonGeometry.fromJson(json, MultiPolygon.class);
// now really check the result
String parsedJson = this.toTest.toJson(jMultiPolygon, MultiPolygon.class);
// as we can't compare the input JSON string due to blanks and ordering, so compare it with the generated string
String expectedJson = "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[15.0,20.0],[16.0,21.0]]],[[[11.0,24.4],[11.0,18.6]]]]}"; //$NON-NLS-1$
assertThat(parsedJson, equalTo(expectedJson));
}
Obviously in geogson-core the MultiPolygon is created by positions
and thus the inner Polygon is not checked.
This minimal example demonstrates the parsing of a MultiPolygon:
The above code give the following exception: