Skip to content
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

Serializers for GeoJson classes [DATAMONGO-2336] #3191

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

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 5, 2019

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)

@christophstrobl
Copy link
Member

@christophstrobl christophstrobl commented Feb 22, 2021

Resolved for 3.2 via #3517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants