-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Use with MongoDB #99
Comments
Hi, this sounds like an issue with how the Mongo driver does deserialization. I'm no Mongo expert, but I'm guessing that the driver doesn't use Json.Net under the hood which this library as built for. I just tried this:
using a POCO
and it works with no issues. |
Hi @fredgate , did you get anywhere with this? Is there any help I can offer? |
Cannot save Polygon to MongoDB 3.6. Using latest GeoJSON.Net version, available today. Any suggestions? |
I'm struggling with this as well. I'm experimenting registering class maps (BsonClassMap.RegisterClassMap) for each relevant class in GeoJSON.NET package. I would like to have House come through WebAPI and serialize it straight like that into MongoDB:
However some fields such as type and coordinates are not being stored in Mongodb. EDIT: ended up writing my own POCOs for GeoJSON. If I tried using MongoDB C# driver provided GeoJSON, WebAPI wouldn't work. With these, Mongo serialization wouldn't work. |
@antonsimola same issue here. Would you be able to share your POCOs to save reincarnation on my end? |
Hi @fredgate, @antonsimola and @darbio, I looked at this back when the issue was first opened. I did start looking at a Contrib library "GeoJSON.Net.Contrib.MongoDB" thats was my idea anyway. I remember that I was finding it hard working out how the c# driver worked. Now I have some time I will have another look. Any help or code examples would be great, think getting something working for Mongodb would be an advantage |
Encountering this issue also, maybe due to too many levels of nesting? (we are using quite big documents) |
After getting stuck on this myself here is my solution.
Or of couse you can use a class map instead of an attribute
|
For those still looking for a solution, I have created a MongoDB.NetTopologySuite.Serialization package which adds support for serializing/deserializing NetTopologySuite models to BSON and back. |
This library is nice, but we can not easily use classes like Point, MultiPoints... in our POCO mapped to MongoDB document.
Imagine a document like that :
Deserialization of document by C# MongoDB driver fails because it cannot deserialize the position embedded document as the type field does not exists in the Point class : there is no type attribute, neither setter for Type property.
Error message is :
FormatException: An error occurred while deserializing the Position property of class MyProject.MyClass : Element 'type' does not match any field or property of class GeoJSON.Net.Geometry.Point.
Can we consider to have a private setter on Type property. The property could be available in the abstract base class GeoJSONObject, and its constructor could take the type as parameter and set it.
So geometry classes could be simplified like this :
What do you think ?
The text was updated successfully, but these errors were encountered: