alibaba / HandyJSON

A handy swift json-object serialization/deserialization library
Other
4.22k stars 615 forks source link

Calling the toJSONString method with UIColor.clear will result in an error #486

Open jijiucheng opened 1 year ago

jijiucheng commented 1 year ago

Question

Calling toJSONString after creating an object with the UIColor.clear property reports an error and fails to serialize successfully.

Code

class SandBoxModel: HandyJSON {
    var mode: Int = 0
    var color: UIColor = .clear

    func mapping(mapper: HelpingMapper) {
        mapper <<<
            color <-- HexColorTransform()
    }

    public required init() {}
}

var model = SandBoxModel()
model.color = .clear
if let jsonString = model.toJSONString {
    print(jsonString)
}

Error

Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range