Closed md81 closed 2 years ago
@md81 ,I'd rather agree with you. I tumbled accross this (https://github.com/moneyphp/money/pull/86), and in particular this commit d2a3320022511687962daf8d6ddb376786d327f3.
From what I see, the Symfony Denormalizer will fai lto denormalize a Money/Money normalized object when using JsonSerializableNormalizer, since the code field is absent in currency field.
While I agree that we could have a debate on the serialization structure, I do not think the current structure is problematic. There is no information missing. It is flattened, which could cause problems with automatic (de)serializers that follow the code structure, but that is a problem outside this package.
Besides, interface {}
exists for a reason, you can create (de)serializers yourself implementing an interface from your framework, solving (de)serialization Money objects for your particular issue.
Hi,
maybe I am wrong but I think serialization result of Money object should looks like:
{"amount": "720000", "currency": {"code": "EUR"}}
instead of:
{"amount": "720000", "currency": "EUR"}
Why? Because for example deserialization usually relay on class's constructor, so if
\Money\Currency
haspublic function __construct(string $code)
then in this case deserializer will look for
code
property in JSON, and in fact won't find.Am I right?