-
Notifications
You must be signed in to change notification settings - Fork 92
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
Serializer Config #136
Serializer Config #136
Conversation
Hi @adrum |
This would be cool to have since it gives flexibility over how you wanna serialize money values by default. E.g. I only need to include amounts in my response, so now in order to achieve that I have to always format them manually, while this feature allows me to set it once and money values will be serialized in my responses as I need. |
@hasfoug that's exactly the use case I had. We just needed the decimal amount and not the full money object parts. The project I used this on did not need currency included when serializing our Money values. We are already using this branch in our project months prior to the initial PR creation, so I figured I would formalize it for a PR to see if there was interest in upstreaming it. It in theory supports providing serializer class, in case the options available do not meets someone's needs. |
this is useful when the model is serialized and deserialized ex: direct binding as livewire property or queue job when the model has to be passed as array and then build using new Model(array). As the serialization generate an array for the field when the "new model" is used the cast throw an error. This could be solved with this pr or adding in each cast the check for array and validating the amount value with the type of the cast |
@adrum could you add tests? |
@ricardogobbosouza We should be good to go with tests! Let me know if you think of anything else. |
Thanks @adrum |
This allows for multiple serialization formats. It keeps the default while allowing other serialization types, such as decimal, integer and intl.