I am having an issue of how to structure my geolocation object in my ASP.NET Core 3 application using the mongodb.driver
My object
public class Person
{
[BsonId]
public ObjectId Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
public string PhoneNumber { get; set; }
public GeoJsonPoint<GeoJson2DGeographicCoordinates> Location { get; set; }
}
I am just doing a straight insertone and passing the object. If I leave out the location it inserts find.
Here is the JSON object I am trying to pass to the api in a simple post.
{
"firstName": "Paul",
"lastName": "Staley",
"email": "[email protected]",
"address": "12345 E 1st Ave",
"state": "AA",
"zipCode": "11111",
"phoneNumber": "555-555-5555",
"location": {
"coordinates": [
0.123321,
0.3453455
]
}
}
The error I get.
System.NotSupportedException: Deserialization of reference types without parameterless constructor is not supported. Type 'MongoDB.Driver.GeoJsonObjectModel.GeoJsonPoint`1[MongoDB.Driver.GeoJsonObjectModel.GeoJson2DGeographicCoordinates]'
var location = new GeoJsonPoint<GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(32.0, 91.0));:: this will show you what is expected.