Repository navigation
fix: Support all serverpod types in Map keys. - #1799
Conversation
093cf0c to
3e6d8af
Compare
|
Yes, I was just about to file an issue/feature request for this - we should at least be able to have ints as Map keys. Only having Strings is way too limiting and there are a lot of use cases I currently have where I need int keys. |
|
Also if we currently CAN have ints as Map keys as your PR description seems to suggest (?) then the documentation is definitely wrong as it says only non-nullable Strings are currently supported. |
|
You are correct! the documentation is wrong here. ints already work! |
|
Do enums that are serialized by name already work too? Reason I'm wondering is that I'm currently encountering a bug with some serializable classes I have with Map fields, in one case it's with int keys, and in another its with enum (serialized byName) keys. When these maps are empty it causes the serverpod deserializer to mess up and try to typecast the Map and a List and crashes, becuase it seems behind the scenes these Maps are being represented as Lists (with items as Maps of "k":blah, "v":blah"), which seems to work when it's not empty but crashes when empty. I thought this might just because I was using officially 'unsupported' Map key types here (ints and String enums) but if they are supported then I need to file a separate issue for this. OK this is actually a lot of description, sorry for all this, I probably should just go ahead and file an issue instead of here. (UPDATE: I created an issue for this: #1806 ) |
|
@jason-downs Thank you for the issue!
They work but not as a key in a Map, until this PR is merged. |
SandPod
left a comment
There was a problem hiding this comment.
Awesome work! Really happy to see all these tests being added and that we finally provide a proper toJson interface.
I have a couple of question.
It was my mistake to review this PR commit by commit. There are a couple of comments that then become outdated.
I still think it would be helpful in the future to squash together amending commits that fix issues in the same. PRs are a great way to preserve documentation around how changes are introduces and the motivation behind them. And bug fixing seldom add much value.
So making them as easy as possible to understand is a small effort that I believe helps future developers :)
Changes
Motivation: For upcoming changes to how we handle relational resolution we have to call resolve this Map for these keys. It makes the most sense to be consistent and making sure the entire tree is built the same way. This approach also aligns with how all other dart toJson implementations are done.
Closes: #1806
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
None