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

Create a base model and generic serialization. #144

Merged
merged 3 commits into from
Jul 21, 2023

Conversation

eseglem
Copy link
Collaborator

@eseglem eseglem commented Jul 21, 2023

@vincentsarago This is what I ended up doing based on #143

I realized all of the classes included BBox and the GeoInterfaceMixin, so combined it all in one new base.

I added a class variable __exclude_if_none__ that is used to determine which fields are excluded. Not particularly invested in the name, was just what I came up with. Also considered starting it with __geojson_pydantic to be a bit closer to some of the __pydantic ones.

Its getting late and my brain has quit on me. I think there were more tests I wanted to add but I will have to take another look in the morning.

Copy link
Member

@vincentsarago vincentsarago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥 it looks great 🥳

I'll start working on a migration guide in another PR, you can merge this PR when you're ready.

Maybe we can have 1.0 release this week 🥳


ref: https://gist.github.com/sgillies/2217756#__geo_interface
"""
return self.model_dump(mode="json")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was a nice little fix here when I realized the old exclude_unset=True was potentially problematic. Not so much on the Geometry types, but on Feature / FeatureCollection it could affect Properties if someone has defaults set in that model.

@vincentsarago
Copy link
Member

I added a class variable exclude_if_none that is used to determine which fields are excluded. Not particularly invested in the name, was just what I came up with. Also considered starting it with __geojson_pydantic to be a bit closer to some of the __pydantic ones.

it might be safer to put something more specific, we can just go with __geojson__exclude_if_none__ but I'll be ok if we don't change 👍

@eseglem eseglem merged commit 2fda6cc into developmentseed:CustomSerializer Jul 21, 2023
5 checks passed
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.

2 participants