moneyphp / money

PHP implementation of Fowler's Money pattern.
http://moneyphp.org
MIT License
4.63k stars 441 forks source link

Fix Money\Currency Json serialization #625

Closed jaumebecks closed 3 years ago

jaumebecks commented 3 years ago

Currency JSON serialization should return an indexed array, as it should be treated as an object in JSON. Therefore, when serializing a Money object, the result should be like

"moneyInstance": {
    "amount": "1000",
    "currency": { 
        "code": "EUR"
    }
}

Instead of

"moneyInstance": {
    "amount": "1000",
    "currency":  "EUR"
}
sagikazarmark commented 3 years ago

Currency JSON serialization should return an indexed array, as it should be treated as an object in JSON.

I don't think that's necessarily true. The format is arbitrary, nothing says the currency has to be an object. Additionally, this is a breaking change.

jaumebecks commented 3 years ago

@sagikazarmark It's true that it is a breaking change, and that shouldn't be an impediment to try to improve the code.

And following the current Entity structure, the default Object formatting should respect the JSON serialization. Money::$currency is a Currency object, and should be reflected as so in JSON, otherwise serialization/deserialization need special serializers/deserializers to manipulate the data. Another thing is that it's intended to apply such change

frederikbosch commented 3 years ago

Unnecessary breaking change. Closing.