Repository navigation
feat: Implement support for polymorphism on endpoints - #4227
Merged
marcelomendoncasoares merged 10 commits intoNov 17, 2025
Merged
marcelomendoncasoares merged 10 commits into
marcelomendoncasoares merged 10 commits into
Conversation
…ializable classes
This comment was marked as resolved.
This comment was marked as resolved.
marcelomendoncasoares
force-pushed
the
polymorphism-on-endpoints
branch
from
November 15, 2025 01:54
e53a250 to
2637ae3
Compare
marcelomendoncasoares
marked this pull request as ready for review
November 15, 2025 02:12
SandPod
reviewed
Nov 17, 2025
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Solution looks good!
I'm, however, missing some backwards compatibility tests to ensure that the serialization format used in Serverpod 1.x and 2.x is still supported.
Perhaps manually calling an endpoint with the old format can validate that the response is parsed correctly?
And what is our view on porting our streaming methods over to use this format? We could save some space by not using the old serializeByClassName. There is no code modifying that flow at the moment.
SandPod
approved these changes
Nov 17, 2025
SandPod
left a comment
Contributor
There was a problem hiding this comment.
BIG! 🙌
cc: @BenAuerDev 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the missing piece for model inheritance on the Serverpod framework: support for polymorphism on the serialization for non-streaming endpoints. The feature implementation consisted in:
__className__field to the JSON serialization of all models carrying the name of the model.Protocol().deserializecheck for such field and calldeserializeByClassNameif present.List,SetandMapon theProtocol().deserializemethod instead of directly inside thefromJsonmethod of each class.The central piece on the polymorphic deserialization is the
deserializeByClassNamemethod, which was already implemented for usage in the streaming endpoints with the exact feature of parsing the model from the specifiedclassName- that now goes inside the JSON.Closes #2909.
During development, two bugs were found and fixed in the serialization of models:
Fixes: #4135
Fixes: #4205
Since these fixes were blocking of this feature and would also touch all of the models, it was preferred to solve them here together instead of creating a blocker and conflicts.
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
The implementation is fully backwards compatible and introduces no breaking changes.