Error: Failed to deserialize Geometry object because 'type' property is either absent or has invalid value.
See original GitHub issueI am trying to store geospatial data in my cosmos db container named Trips and retrieve the items from my .net core web api (.net 5). I am using Microsoft.Azure.Cosmos (3.19.0) and have not configured anything explicitly for serializing. The save works but when I try to retrieve I am getting this error:
Newtonsoft.Json.JsonSerializationException: Failed to deserialize Geometry object because ‘type’ property is either absent or has invalid value.
Cosmos Client Instance:
var options = new CosmosClientOptions()
{
AllowBulkExecution = true,
SerializerOptions = new CosmosSerializationOptions()
{
PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
}
};
var cosmosClient = new CosmosClient(account, key, options);
Model:
public class Trip
{
[JsonPropertyName("id"), Required]
public string Id { get; set; }
[JsonPropertyName("vehicleId"), Required]
public string VehicleId { get; set; }
[JsonPropertyName("startDateTime"), Required]
public DateTime StartDateTime { get; set; }
[JsonPropertyName("endDateTime"), Required]
public DateTime EndDateTime { get; set; }
[JsonPropertyName("wayPoints"), Required]
public List<WayPoint> WayPoints { get; set; }
}
public class WayPoint
{
[JsonPropertyName("timeStamp"), Required]
public DateTime TimeStamp { get; set; }
[JsonPropertyName("point"), Required]
public Point Point { get; set; }
}
Service:
public async Task<IEnumerable<Trip>> GetMultipleAsync(string vehicleId = "")
{
var queryDefinition = new QueryDefinition($"Select * from c where c.vehicleId = \"{vehicleId}\"");
var queryIterator = _container.GetItemQueryIterator<Trip>(queryDefinition);
var trips = new List<Trip>();
while(queryIterator.HasMoreResults)
{
var response = await queryIterator.ReadNextAsync();
trips.AddRange(response.ToList());
}
return trips;
}
Json sample:
{
"id": "a9153ca0-e171-4fe8-bcfe-733ac75f6b85",
"vehicleId": "599abc63-eafb-4015-ac65-fc6aed48d9aa",
"startDateTime": "2021-06-17T00:00:00Z",
"endDateTime": "2021-06-17T23:55:00Z",
"wayPoints": [
{
"timeStamp": "2021-06-17T00:00:00Z",
"point": {
"Position": {
"Coordinates": [
51.23156579100001,
-0.603818000999999
],
"Longitude": 77.23156579100001,
"Latitude": 12.016038180009999,
"Altitude": null
},
"Crs": {
"Type": 0
},
"Type": 0,
"BoundingBox": null,
"AdditionalProperties": {}
}
},
{
"timeStamp": "2021-06-17T00:05:00Z",
"point": {
"Position": {
"Coordinates": [
51.23159449100001,
-0.01703846700999
],
"Longitude": 77.23159449100001,
"Latitude": 12.603846700999998,
"Altitude": null
},
"Crs": {
"Type": 0
},
"Type": 0,
"BoundingBox": null,
"AdditionalProperties": {}
}
},
////////////
{
"timeStamp": "2021-06-17T23:55:00Z",
"point": {
"Position": {
"Coordinates": [
51.23980269100042,
-0.01961205490099
],
"Longitude": 77.23980269100042,
"Latitude": 12.612054900999901,
"Altitude": null
},
"Crs": {
"Type": 0
},
"Type": 0,
"BoundingBox": null,
"AdditionalProperties": {}
}
}
],
}
Any help would be appreciated. Thanks!
Environment summary SDK Version: 3.19.0 OS Version: Windows 10
I have also posted this issue in stack overflow but no luck so far.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Microsoft.Azure.Cosmos.Spatial Error while deserializing ...
Newtonsoft.Json.JsonSerializationException : Failed to deserialize Geometry object because 'type' property is either absent or has invalid value.
Read more >spatial data types not serializing JSON properly · Issue #1981
This very clearly says why the JSON serialization is failing - the NetTopologySuite object contains a circular reference, which isn't possible ...
Read more >Problem to deserialize object with jackson · Issue #1865
Hi guys, I have two applications, one read and another write on redis: My entity @Data ... Object]: missing type id property '@Class'...
Read more >How to deserialize geoJon input to locationtech.jts.geom. ...
Geometry is org.locationtech.jts.geom.Geometry. I have following pom dependency: <dependency> <groupId>com.graphhopper.external</ ...
Read more >Geometry Class (Microsoft.Azure.Cosmos.Spatial)
Determines if the geometry specified is valid and can be indexed or used in queries by Azure Cosmos DB service and if invalid,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for taking time to give this detailed explanation and responding to my queries @ealsur. This helps.
I see, so there are 2 points.
One is, how do you generate a Json file that you can upload on the Azure Portal with the right casing. I think the problem is you are mixing serialization technologies.
If you are generating a Json file and uploading, you are in full control of what that content is and the SDK is not related at all. The key point there though is that you seem to be using System.Text.Json to generate the File content. The
JsonSerializer.SerializeAsync
seems to be coming from System.Text.Json, right? The V3 SDK uses Newtonsoft.Json as serialization technology and the Geometry classes all have decorators for Newtonsoft.Json. So if you are generating the raw Json file for Portal upload, use Newtonsoft.Json instead of System.Text.Json.The second aspect is Bulk. If you are using Bulk (this also means turning on the Bulk mode) then the performance will always be much faster than uploading it through the Portal. You can see some benchmark results at https://github.com/Azure/azure-cosmos-dotnet-v3/pull/2440. When the client is on Direct mode, it is directly reaching the backend replica. Uploading a file through the Portal and having the Portal save the file contents as documents as requests being sent from the browser cannot be faster than accessing the Replica through a connected TCP channel. Make sure your Controller is async and that the client is on Bulk mode. You can monitor the RU consumption also and see if you are getting any 429/Throttles (Bulk mode might be even pushing data faster than your provisioned throughput can process it and causing throttling).