Skip to content

add custom serializer to match GeoJSON spec #143

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

Merged
merged 5 commits into from
Jul 21, 2023
Merged

Conversation

vincentsarago
Copy link
Member

closes #125

@vincentsarago vincentsarago requested a review from eseglem July 20, 2023 12:37
@vincentsarago vincentsarago changed the title ad custom serializer to match GeoJSON spec add custom serializer to match GeoJSON spec Jul 20, 2023
@eseglem
Copy link
Collaborator

eseglem commented Jul 21, 2023

I like the idea, but have been trying to think through all the implications. A bit worried about ignoring any of the serialization kwargs that are used, and I don't entirely know how things are handled when nested due to not having much documentation on it. Especially when it comes to how Properties will be handled.

I managed to get this to work. It calls the built in serializer then removes the field from the result.

    @model_serializer(when_used="json", mode="wrap")
    def clean_model(self, serializer: Any, _info: SerializationInfo) -> Dict[str, Any]:
        """Custom Model serializer to match the GeoJSON specification."""
        data: Dict[str, Any] = serializer(self)
        if "bbox" in data and data["bbox"] is None:
            del data["bbox"]
        return data

Which led me to attempting to make it more generic, and a rabbit hole of additional generalization... I'll probably throw up a PR soon to see what you think.

@vincentsarago vincentsarago merged commit 08f3d1b into main Jul 21, 2023
@vincentsarago vincentsarago deleted the CustomSerializer branch July 21, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bbox behavior different from spec
4 participants