diff --git a/Microsoft.Azure.Cosmos/src/Spatial/Converters/GeometryJsonConverter.cs b/Microsoft.Azure.Cosmos/src/Spatial/Converters/GeometryJsonConverter.cs index 85b58be06b..47b08d14b1 100644 --- a/Microsoft.Azure.Cosmos/src/Spatial/Converters/GeometryJsonConverter.cs +++ b/Microsoft.Azure.Cosmos/src/Spatial/Converters/GeometryJsonConverter.cs @@ -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); } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Spatial/CommonSerializationTest.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Spatial/CommonSerializationTest.cs index b71a0a07fe..be73dab37c 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Spatial/CommonSerializationTest.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/Spatial/CommonSerializationTest.cs @@ -29,6 +29,17 @@ public void TestInvalidJson() Point point = JsonConvert.DeserializeObject(json); } + /// + /// Tests that no type throws exception. + /// + [TestMethod] + [ExpectedException(typeof(JsonSerializationException))] + public void TestNoType() + { + string json = @"{""notatype"":""nothingrelevant""}"; + Point point = JsonConvert.DeserializeObject(json); + } + /// /// Tests that coordinates cannot be null. ///