tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.14k stars 1.03k forks source link

Convert Object to JSON Objects inited in init #1050

Open maasim94 opened 5 years ago

maasim94 commented 5 years ago

I have an object for which there are some properties in init func, while parsing data from JSON to object, it is doing great but while converting Object to JSON, i could not find way to convert that data in JSON

Following is code i'm using

var sOWSubCategory: SowSubCategoryModel?
var reportDisplayId : String?

required init?(map: Map){
        sOWSubCategory = SowSubCategoryModel(sOWSubCategoryID: map.JSON["SOWSubCategoryID"] as? Int, sOWSubCategoryNameAr: map.JSON["SOWSubCategoryNameAr"] as? String, sOWSubCategoryNameEn: map.JSON["SOWSubCategoryNameEn"] as? String)
        sOWSubCategoryDetail = SowSubCategoryDetailListModel(sOWSubCategoryDetailID: map.JSON["SOWSubCategoryDetailID"] as? Int64, sOWSubCategoryDetailAr: map.JSON["SOWSubCategoryDetailNameAr"] as? String, sOWSubCategoryDetailEn: map.JSON["SOWSubCategoryDetailNameEn"] as? String)
    }
func mapping(map: Map) {
    reportDisplayId <- map["ReportDisplayID"]   
}

reportDisplayId is being converted to JSON, but sOWSubCategory and sOWSubCategoryDetail are not