[JAVA-3105] Following the RFC, Position should be a list of double, not an object containing a list of double Created: 30/Nov/18  Updated: 27/Oct/23  Resolved: 11/Jan/19

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

Type: Task Priority: Major - P3
Reporter: Julien Deruere Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When decoding a Geometry, I end up having this structure from Mongo Geometry codecs: 

 

"geometry": { "coordinates": [ { "values": [ -4.7953494, 37.9414098 ] }, { "values": [ -4.7954192, 37.9415325 ] }, { "values": [ -4.7956498, 37.9416594 ] }, { "values": [ -4.7958376, 37.9418286 ] }, { "values": [ -4.7960897, 37.9419851 ] }, { "values": [ -4.7963418, 37.9421586 ] }, { "values": [ -4.7966208, 37.9422136 ] }, { "values": [ -4.7970285, 37.9422982 ] }, { "values": [ -4.7973343, 37.9423701 ] }, { "values": [ -4.7975381, 37.9424886 ] }, { "values": [ -4.7976929, 37.9425605 ] }, { "values": [ -4.7980102, 37.9424463 ] } ], "type": "LINE_STRING" }

 

 

When I more expecting this: 

 

"geometry": {
            "coordinates": [
                 [
                        -4.7953494,
                        37.9414098
                    ]
                ,
                 [
                        -4.7954192,
                        37.9415325
                    ]
                ,
                 [
                        -4.7956498,
                        37.9416594
                    ]
                ,
                 [
                        -4.7958376,
                        37.9418286
                    ]
                ,
                 [
                        -4.7960897,
                        37.9419851
                    ]
                ,
                [
                        -4.7963418,
                        37.9421586
                    ]
            ],
            "type": "LINE_STRING"
        }

Following the RFC:

https://tools.ietf.org/html/rfc7946#section-3.1.1



 Comments   
Comment by Jeffrey Yemin [ 01/Dec/18 ]

You're using Jackson to encode the driver's Geometry POJO's to JSON, but those POJOs don't have Jackson annotations. So, for example, the LineString class contains the field List<Position> values, and the Position class contains the field List<Double> values. Jackson is encoding instances of these classes as JSON using its default behavior, which produces the output you mentioned above.

You may be able to get the behavior you want by writing Jackson mix-in annotations or custom serializers for the Geometry-related classes.

Comment by Julien Deruere [ 30/Nov/18 ]

I was actually more talking about encoding the Geometry Object to RFC7946 compatible JSON.

Comment by Julien Deruere [ 30/Nov/18 ]

Hi, 

I'm trying to develop on API that answer pure geojson object like Feature and Feature Collection, so I wrapped the com.mongodb.client.model.geojson.Geometry into a Feature POJO:

public class Feature extends GeoJsonObject {
 
    private Geometry geometry;
    private Map<String, Object> properties = new HashMap<>();
 
    @BsonCreator
    @JsonCreator
    public Feature() {
        super();
    }
 
    public Geometry getGeometry() {
        return geometry;
    }
 
    @JsonProperty("geometry")
    @BsonProperty("geometry")
    public void setGeometry(Geometry geometry) {
        this.geometry = geometry;
    }
 
    public Map<String, Object> getProperties() {
        return properties;
    }
 
    @JsonProperty("properties")
    @BsonProperty("properties")
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }
}

And then I'm doing this:

public Single<List<Feature>> fetch(String type) {
    return Flowable.fromPublisher(db.getCollection("Feature", Feature.class).find()).toList();
}

Should I develop a specific codec?

Comment by Jeffrey Yemin [ 30/Nov/18 ]

Hi jderuere

Thanks for the report. The com.mongodb.client.model.geojson.codecs.LineStringCodecSpecification#should round trip test indicates that it works as you expect.

Would you be able to provide a snippet of Java code that reproduces the problem?

Thanks,
Jeff

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