Skip to content
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

Deserialize MultiPolygon Array of Empty Coordinates Array #140

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public static StjParsedCoordinates Parse(ref Utf8JsonReader reader, GeometryFact
reader.AssertToken(JsonTokenType.StartArray);
reader.ReadOrThrow();

if (reader.TokenType == JsonTokenType.EndArray)
{
reader.ReadOrThrow();
if (reader.TokenType == JsonTokenType.EndArray)
{
return new StjParsedCoordinates(factory.CreateMultiPolygon(new Polygon[] { factory.CreatePolygon() }));
}
}

if (reader.TokenType == JsonTokenType.Number)
{
return new StjParsedCoordinates(ParseCoordinateSequence(ref reader, factory));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public void TestReadWithEmptyCoordinatesArray(string type)
Assert.That(geom.IsEmpty);
}

[TestCase]
public void TestMultiPolygonReadWithArrayOfEmptyCoordinatesArray()
{
string geoJson = @"{ ""type"" : ""MultiPolygon"", ""coordinates"": [ [] ] }";
var options = DefaultOptions;
var geom = Deserialize(geoJson, options);

Assert.That(geom != null);
Assert.That(new MultiPolygon(new Polygon[] { new Polygon(null) }) == geom);
Assert.That(geom.IsEmpty);
}

[GeoJsonIssueNumber(57)]
[TestCase("{\"type\": \"Point\", \"coordinates\": [], \"bbox\": null}")]
[TestCase("{\"type\": \"LineString\", \"coordinates\": [], \"bbox\": null}")]
Expand Down
Loading