Skip to content

Instantly share code, notes, and snippets.

@vhart
Last active August 28, 2017 21:14
Show Gist options
  • Save vhart/d2a1ec10028e086459e888b8f44632b5 to your computer and use it in GitHub Desktop.
Save vhart/d2a1ec10028e086459e888b8f44632b5 to your computer and use it in GitHub Desktop.
class BaseJsonDeserializer<T>: JsonDeserializer {
init() {
guard type(of: self) != BaseJsonDeserializer.self
else { fatalError("do not initialize this abstract class directly") }
}
func parse(json: [String : Any]) -> T {
fatalError("Abstract class. Subclass must override")
}
}
class DeserializerBox<D: JsonDeserializer>: BaseJsonDeserializer<D.Response> {
private let deserializer: D
init(concreteDeserializer: D) {
self.deserializer = concreteDeserializer
}
override func parse(json: [String : Any]) -> D.Response {
return deserializer.parse(json: json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment