泛型反序列化问题
Closed this issue · 2 comments
yneear commented
struct Response<Content: Any>: SmartCodable {
var status: String?
@SmartAny
var content: Content?
var errorCode: String?
}
struct Check: SmartCodable {
var token: String?
}
let JSON = """
{"status":"SUCCESS","errorCode":null,"content":{"token":"b3d0e432037d9db9e468a95250dead5c"}}
"""
let resp = Response<T>.deserialize(from: JSON)
HandyJSON 是支持这样的反序列的,但 SmartCodable 会有下面的报错:
======================== [Smart Decoding Log] ========================
Response<Check> 👈🏻 👀
|- content: Expected to decode SmartAny<Optional<Check>> but found a dictionary instead.
=========================================================================
只能通过自定义策略还是有其他的解决方法?
intsig171 commented
intsig171 commented
@SmartAny 是用来修饰Any的,比如Any类型,[String: Any], [Any]. 不能用来修饰一个Model(内部的解析未支持,这并不符合使用场景)