During decoding of ClassA that conforms to Decodable, I would like to retrieve the value of one of the properties for custom decoding. How do I achieve that?
class ClassA: Decodable {
let title: String?
let data: MyCustomNotDecodableNSObject?
private enum CodingKeys: String, CodingKey {
case title
case data
}
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
title = try? container.decode(String.self, forKey: .title)
let dataRawValue = ? // somehow retrieve the raw value that coresponds to the key "data" (JSON string)
let theData = MyCustomNotDecodableNSObject(rawData: dataRawValue)
data = theData
}
}
Example of parsed JSON:
{
"classA" : {
"title" = "a title"
"data" : {
"key1" : "value 1",
"key2" : "value 2",
"key3" : "value 3"
}
}
The thing I am after is:
"key1" : "value 1",
"key2" : "value 2",
"key3" : "value 3"
Please, do not suggest making MyCustomNotDecodableNSObject conform to Decodable protocol. This class cannot be modified.