With RestKit, I'm trying to create a request mapping that would convert a payment object into JSON. This object stores sub-payments, of which only one is valid. This valid payment is represented by the property selectedPayment. I think the typical approach for this is to use a relationship mapping however I don't want the selectedPayment to appear as a nested key. An example of the result of my current approach is below:
{
"requestUserId" : "6",
"payment" : {
"selectedPayment" : {
"amount" : "5",
"id" : 70,
"type" : "SOME_TYPE"
}
}
}
My desired output is the following:
{
"requestUserId" : "6",
"payment" : {
"amount" : "5",
"id" : 70,
"type" : "SOME_TYPE"
}
}
I have tried numerous options for my relationship mapping's destination key path: @root, @parent, "", nil. All of which have resulted in a crash (except "", which nests the selected payment under an empty key).
I could modify the attribute mappings of the request mapping that is used for selectedPayment to explicitly use @root or @parent but this would not be ideal as it would negatively affect other areas that mapping is used.
This seems like typical behaviour, converting a "deep" object representation into a "shallow" JSON representation, surely there is a straightforward way to do it?
Instead of using a relationship mapping, use key paths in your single mapping, navigate into the property and then extract the keys that you seeking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With