Open apankowski opened 2 years ago
I think this was fixed via #17 (and release notes for 2.14.0 refer to it). Closing.
hey @cowtowncoder :slightly_smiling_face:
I believe the functionality described in this enhancement (as it's not really an issue) was not part of #17. In the course of #17 only global selection of the amount representation was done, which applies to (de)serialization of all Money fields. This enhancement pertains to the possibility of overriding the global amount representation for any particular Money field. My goal was to discuss possible approaches in order to select the best one and implement it in the future.
Ah. Ok, will reopen.
Intro
For Joda Money module, we have the possibility to select the amount representation on module level. Amount representation varies from API to API. In projects that involve integration with many APIs it would be beneficial to allow such selection on field-level. This ticket collects possible approaches.
Appoaches
To achieve field-level selection we could:
@JsonFormat
'sshape
(see comment #1 and comment #2):Characteristics:
@JsonFormat
on Money (de)serializers as it won't be obvious whatshape
s are supported and what effect they have.currencyCode
instead ofcurrency
andvalue
instead ofamount
as the names of the individual properties carrying the monetary amount. If we wanted to allow customization of the names in the future, most likely we wouldn't do that via@JsonFormat
annotation but rather a dedicated one.@JsonMoney
) allowing selection of amount representation (see comment):Characteristics:
@JsonFormat
to allow passing (de)serializer-specific annotations (here: via newwith
attribute):Characteristics:
@JsonFormat
just for the sake of passing custom annotations.Implementation
Regardless of the approach, most likely
Contextual(De)Serializer
would be used to build the (de)serializer.Discussion
Do you see some more characteristics of these approaches? Do you see a clear winner? (I'm slightly leaning towards approach 2)
Of course we don't have to pull the trigger now - might as well keep this open until we have more insights or convictions. Just wanted to write down my thoughts.