Skip to content

Serializers for GeoJson classes [DATAMONGO-2336] #3191

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

Closed
spring-projects-issues opened this issue Aug 5, 2019 · 1 comment
Closed

Serializers for GeoJson classes [DATAMONGO-2336] #3191

spring-projects-issues opened this issue Aug 5, 2019 · 1 comment
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

kubahorak opened DATAMONGO-2336 and commented

In GeoJsonModule there are deserializers present.

See Line 55

These allow deserialization from RFC7946 format to GeoJson classes.
 

Serializing GeoJsonMultiPoint (applies also to other GeoJson classes) with Jackson using GeoJsonModule leads to following JSON:

 

{
    "coordinates": [
        {
            "coordinates": [
                13.306671,
                52.475053
            ],
            "type": "Point",
            "x": 13.306671,
            "y": 52.475053
        },
        {
            "coordinates": [
                13.3063,
                52.470674
            ],
            "type": "Point",
            "x": 13.3063,
            "y": 52.470674
        }
    ],
    "type": "MultiPoint"
}

 

RFC7946 Section 3.1.3Section 3.1.1 and Appendix A.4 specifies that the coordinates should be an array of numbers, not a list of Points.

Expected result would be:

{
    "coordinates": [
        [
            13.306671,
            52.475053
        ],
        [
            13.3063,
            52.470674
        ]
    ],
    "type": "MultiPoint"
}

To fix this, I suggest adding serializers to GeoJsonModule.

See following test case:

 

GeoJsonMultiPoint multipoint = new GeoJsonMultiPoint(
    new Point(0, 0),
    new Point(1, 1));
String result = objectMapper.writeValueAsString(multipoint);
assertThat(result).isEqualToIgnoringWhitespace(
    "{ \"type\": \"MultiPoint\", \"coordinates\": [[0.0, 0.0], [1.0, 1.0]] }"
);

 

 


Affects: 2.1.10 (Lovelace SR10)

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: mapping Mapping and conversion infrastructure labels Dec 30, 2020
@christophstrobl
Copy link
Member

Resolved for 3.2 via #3517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants