[JAVA-2247] Support decoding of GeoJSON objects Created: 14/Jul/16  Updated: 25/Apr/17  Resolved: 25/Apr/17

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: None
Fix Version/s: 3.5.0

Type: New Feature Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on JAVA-2264 Support constructor based serialization Closed
Duplicate

 Description   

Currently the GeoJson class hierarchy can be encoded, but not decoded. See com.mongodb.client.model.geojson.codecs.PointCodec for example, in which encode is implemented, but not decode. Basically this means that you can insert or query for data using this class hierarchy, but that's about it.

This makes sense currently because the driver doesn't support decoding to POJOs natively yet. But when we do it would be nice to be able to handle POJO's like:

public class MyPOJO {
   private Point myPoint;
   private List<Point> yourPoints;
 
   ...
}

For that to work we'll need to implement the decode methods in all the GeoJSON codecs.



 Comments   
Comment by Githook User [ 25/Apr/17 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Implemented decode methods for the Geometry codecs

JAVA-2247
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/5ff9c7d1354a286503e61590c59f18517432570e

Comment by Ross Lawley [ 11/Apr/17 ]

PR: https://github.com/rozza/mongo-java-driver/pull/181

Comment by Ross Lawley [ 27/Mar/17 ]

The pojo codec won't be able to handle decoding automatically due to the removal of constructor based support, so this should be implemented in the individual codecs.

Comment by Ross Lawley [ 21/Feb/17 ]

I agree that GeoJson codecs should be updated to handle decoding then they could be used by the PojoCodec. Potentially the constructor based decoding in the PojoCodec could be used here but it may add a discriminator resulting in a differently shaped document.

I'm removing the POJO epic flag as this is related but not actually required for the PojoCodec.

Comment by Jeffrey Yemin [ 14/Jul/16 ]

I should elaborate on one point. A GeoJson object is just a BSON document. It doesn't have its own type. So a Point, for example, is encoded like this within a containing BSON document:

{ 
   myPoint: {type: 'Point', coordinates: [40.0, 18.0]}
}

When the driver decodes this to a Document or a DBObject, it has no good way of knowing that the value of myPoint is actually a GeoJSON object and should be decoded as such. So it will just decode it as a Document or DBObject. To do it right, we really need POJO support.

Generated at Thu Feb 08 08:56:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.