I have a requirement in which I must have property that can bind it’s value by "debtAmount" or "Amount"
I did try to have annotation from above, and it works for debtAmount but value won’t bind using "amount"
I want to achieve one an optional binding for one property (either by amount or debtAmount)
2
Answers
if you want multiple JSON properties during deserialization, you can use
JsonConverter
During
Deserialize
use thisNewAccountRequestJsonConverter
as optionsOne approach, already presented is to put some mapping logic inside JsonConverter (inherit from it and override some logic).
Second approach, as I see, could be mapping both fields to their respective fields
Amount
anddebtAmount
and have some method to fetch that info based on both properties, something along those lines:You would need to make amount fields nullable, to detect when they’re not provided at all. Or you can treat default value of
0
as "empty value", if 0 won’t be valid number.