-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Custom type in array key is not respected when serializing to JSON #1223
Comments
I managed to work around this problem by creating a new custom type to handle serialization of this kind of array. |
type handlers on the array keys is something that is not supported (as min most of the cases keys are simple scalars as integers or strings). |
So the docs is misleading about this. It states Based on this, I thought that any type K would work. But, in fact, type K is only used for deserializing and it's completely ignored when serializing. Maybe adding a note in the docs could clarify this limitation. |
It would be great if you could add a note in the documentation about this (https://github.com/schmittjoh/serializer/tree/master/doc/reference) |
solved in #1235 |
I have a property annotated with key-value syntax for array, like
@Type("array<K, V>")
, whereK
is a custom type I defined. When a JSON is deserialized, the key is passed to my custom handler and it gets deserialized, as expected. But when it is serialized back to JSON, the custom handler is not called and the key is used as-is in the JSON output.The custom type was defined to handle a map where the key was a database ID. In the API I'm working, all database IDs should be converted using Hashids. This handler is working well in other places, it just does not work for array keys. Also, I'm not sure how this might affect other formats, such as XML, as I'm only using JSON.
Steps required to reproduce the problem
I have created a small repo reproducing this problem: https://github.com/eduardoweiland/jmsserializer-json-map-key-transform
Expected Result
Actual Result
The text was updated successfully, but these errors were encountered: