Closed luissalgadofreire closed 2 years ago
Sure it's totally possible to introduce that, one thing I would suggest is to re-use the name
attribute to pass your prefix value,
to not introduce custom prefix
attribute for one use case only. What do you think?
When flatten: true
, name:
does not have any sense, and we will bring that sense as a prefix
@jsonSerializable
class Account {
final String id;
final String type;
final String subtype;
final String origin;
final String name;
final String status;
final String currency;
@JsonProperty(flatten: true, name: 'balance')
final Money balance; <== value object
...
}
Thank you for the idea!
Thanks for the quick reply.
So, in this context, name
would work as a prefix, added before currency
and amount
, and these would be capitalized, with end result balanceCurrency
and balanceAmount
, as in the example?
Sounds ok with me.
By the way, I haven't tested it yet. Does flatten
work multiple levels deep?
Any way, thanks for this great library.
By the way, I haven't tested it yet. Does
flatten
work multiple levels deep?
No, one level so far.
The casing aspect can be configured at a higher level, please read more here
balanceCurrency
and balanceAmount
would be a good fit for CaseStyle.camel
OK, great.
I'm moving from json_serializable
, so still have to get acquainted with this library in more detail.
Thanks again for the quick response.
Delivered. Merry Christmas ☃️ 🎄
Great stuff. Thanks.
Best wishes.
I have a dart object that includes a field of type
Money
, which itself is composed ofamount
andcurrency
:Money
looks something like this:The above is to be mapped for use by
sqflite
, therefore the target JSON must be a flat JSON, like:I understand I can use
@JsonProperty(flatten: true)
to make it work closely to what I need. But to avoid conflict with otherMoney
instances I may have in the source object, a prefix would come handy.Would it be possible to have something like:
That way,
dart-json-mapper
would know that it would have to prefixbalance
to the names of propertiescurrency
andamount
ofMoney
, resulting in the above mentioned JSON: