Skip to content

Encodable also send nil values #2

@mansoor92

Description

@mansoor92

public class ProductInput: Serializable {
@serialized
public var query: String?
required init() { }
}

//convert to data
let encoder = JSONEncoder()
let data = try! encoder.encode(ProductInput())

//print string
let jsonObject = try! JSONSerialization.jsonObject(with: data, options: [])
let dictionary = jsonObject as! [String:Any]
print(dictionary)

//result
▿ 1 elements
▿ 0 : 2 elements
- key : "query"
- value :

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions