opendatalab-de / geojson-jackson

GeoJson POJOs for Jackson - serialize and deserialize objects with ease
http://blog.opendatalab.de
Apache License 2.0
266 stars 95 forks source link

Conversion from double to string #28

Open LiberQuack opened 8 years ago

LiberQuack commented 8 years ago

After saving a Point into MongoDB I realized it converts double to String

As I know... GeoJSON specify numbers inside the array coordinates. Am I wrong?

grundid commented 8 years ago

Thanks for mentioning this. I haven't tried these classes with MongoDB yet. I would assume that mongo would serialize the LngLatAlt class as an object with several properties instead of an array. Is this right? Could you please share some code and/or how Mongo saves this?

@notanyron in this situation an array for all properties would be better ;)

Babbleshack commented 8 years ago
"geometry" : {
         "type" : "FeatureCollection",
         "features" : [
                 {
                         "type" : "Feature",
                         "properties" : {

                         },
                         "geometry" : {
                                 "type" : "Point",
                                 "coordinates" : [
                                         "36.394900225",
                                         "-24.135984854"
                                 ]
                         }
                 }
         ]
 }

When deserilizing the LngLatAlt object i.e. the coordinates array under geometry, Unexpected token (VALUE_STRING) when binding data into LngLatAlt exception is thrown.

Ruckley commented 7 years ago

I believe the LngLatAltSerializer needs to be fixed as well. If you look at the geoJson specifications position data should be given as an array of doubles not strings. http://geojson.org/geojson-spec.html#geometry-objects

Theres also the problem that the Double to String conversion in LngLatAltSerializer is performed on lng and lat but not alt. So a 3d point ends up with two strings and a double.

I came accorss this problem when I was trying to use geojson generated by this api with MongoDB. MongoDB is designed to work wth the geoJson spec and so cannot create indexes for the generated geoJson as it expects arrays of Doubles not Strings when dealing with locations.

This problem could be corrected by removing the fastDoubleToString method from the LngLatAltSerializer.

Babbleshack commented 7 years ago

Did you fix this?

Ruckley commented 7 years ago

The fix has been merged, LngLatAlt positions serialize to an array of doubles now