I have to decode an object from this JSON:
{
"id": "..."
"someData": { ... },
"elements": {
"values": [
{
"id": "1",
...
},
{
"id": "2"",
...
}
]
}
}
So I have several structs like this:
struct Object: Codable {
let id: String
let someData: SomeCodableObject
let elements: Elements
}
struct Elements: Codable {
let values: [Value]
}
struct Value: Codable {
let id: String
...
}
After filling each element with some data I've to send an object similar to the decoded one but changing "elements" and "values" by "elementQuotes" and "valueQuotes" respectively (yes, I know the API should avoid this weird behavior, but it's not possible...), that is, a JSON like this:
{
"id": "..."
"someData": { ... },
"elementQuotes": {
"valueQuotes": [
{
"id": "1",
...
},
{
"id": "2"",
...
}
]
}
}
Is there any way to achieve this without using different objects (some for decoding and some other for encoding). That is, is there any way to specify different coding keys string values for encoding/decoding
I repeat: I know this is a really bad practice in the API side but ... I've to manage this "feature"
ObjectQuotesandElementsQuotesand be done with it. It would be future proof as well in case if that endpoint gains extra fields that are missing in the original response.