Skip to content

Commit

Permalink
Spatial: Fixes deserialization when Json does not represent a Spatial…
Browse files Browse the repository at this point in the history
… type (#2311)

* when null

* test

Co-authored-by: j82w <j82w@users.noreply.github.com>
  • Loading branch information
ealsur and j82w authored Mar 16, 2021
1 parent 1de5db6 commit 9f9b264
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public override object ReadJson(
}

JToken typeToken = token["type"];
if (typeToken.Type != JTokenType.String)
if (typeToken == null
|| typeToken.Type != JTokenType.String)
{
throw new JsonSerializationException(RMResources.SpatialInvalidGeometryType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public void TestInvalidJson()
Point point = JsonConvert.DeserializeObject<Point>(json);
}

/// <summary>
/// Tests that no type throws exception.
/// </summary>
[TestMethod]
[ExpectedException(typeof(JsonSerializationException))]
public void TestNoType()
{
string json = @"{""notatype"":""nothingrelevant""}";
Point point = JsonConvert.DeserializeObject<Point>(json);
}

/// <summary>
/// Tests that coordinates cannot be null.
/// </summary>
Expand Down

0 comments on commit 9f9b264

Please sign in to comment.