-
Notifications
You must be signed in to change notification settings - Fork 63
Description
Hi,
It's probably easiest for me to explain my use case:
The application that I work on uses an API which sends down information that looks vaguely like this:
{
...
"car": {
"make": "Honda",
"model": "Accord"
}
}
The application itself holds separate caches with rich models referring to "Honda Accord". During parsing, I'd like to deserialize this model into a SimpleCar model, and then perform a lookup in my cache for the richer model, throwing an error if the model is not found.
My feeling is that this should be done during parse time, so I want to be able to add this contextual information to the JSONDecoder. In the current design JSONDecoder is not extensible. What are your thoughts on:
- Making
JSONDecodera protocol - Use a protocol extension to provide all of the JSON parsing functionality we have now
- Provide a
BaseJSONDecodertype implementingJSONDecoder - Add an
associatedtypetoJSONDecodable
protocol JSONDecodable {
associatedtype Decoder: JSONDecoder
...
}I'm sketching this out and I don't see a particular reason why we couldn't do this. Another possibility is making JSONDecoder open to subclassing, which I don't think it is (and object is internal).