Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash in JSONWarehouse during JSON Write #58

Open
alexwald opened this issue Dec 6, 2016 · 6 comments
Open

crash in JSONWarehouse during JSON Write #58

alexwald opened this issue Dec 6, 2016 · 6 comments

Comments

@alexwald
Copy link

alexwald commented Dec 6, 2016

I have the following nested model:

    let id: String
    let agencyId: String
    let name: String
    var checklistItems: [ChecklistItem]

    init (id: String, agencyId: String, name: String, checklistItems: [ChecklistItem]) {
        self.id = id
        self.agencyId = agencyId
        self.name = name
        self.checklistItems = checklistItems
    }

    init(unboxer: Unboxer) throws {
        id = unboxer.unbox(key: "id") ?? ""
        agencyId = unboxer.unbox(key: "agencyId") ?? ""
        name = unboxer.unbox(key: "name") ?? ""
        checklistItems = unboxer.unbox(key: "checklistItems") ?? []
    }
}

extension Checklist: Storable {
    init(warehouse: Warehouseable) {
        self.id = warehouse.get("id") ?? ""
        self.agencyId = warehouse.get("agencyId") ?? ""
        self.name = warehouse.get("name") ?? ""
        self.checklistItems = warehouse.get("checklistItems") ?? [ChecklistItem]()
    }

    func toDictionary() -> [String : Any] {
        return [ "id": self.id, "agencyId": self.agencyId, "name": self.name, "checklistItems": self.checklistItems ]
    }
}

struct ChecklistItem: Unboxable {
    let id: String
    let checklistId: String
    let title: String
    var checked: Bool = false

    init(id: String, checklistId: String, title: String, checked: Bool) {
        self.id = id
        self.checklistId = checklistId
        self.title = title
        self.checked = checked
    }

    init(unboxer: Unboxer) throws {
        id = unboxer.unbox(key: "id") ?? ""
        checklistId = unboxer.unbox(key: "checklistId") ?? ""
        title = unboxer.unbox(key: "title") ?? ""
    }
}

extension ChecklistItem: Storable {
    init(warehouse: Warehouseable) {
        self.id = warehouse.get("id") ?? ""
        self.checklistId = warehouse.get("checklistId") ?? ""
        self.title = warehouse.get("title") ?? ""
        checked = warehouse.get("checked") ?? false
    }

    func toDictionary() -> [String : Any] {
        return [ "id": self.id, "checklistId": self.checklistId, "title": self.title, "checked": self.checked ]
    }
}

checklist.toDictionary() produces the following:

["agencyId": "00000000-0000-0000-0000-000000000001", "id": "00000000-0000-0000-0000-000000000001", "checklistItems": [vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000006", checklistId: "00000000-0000-0000-0000-000000000001", title: "Opaľovací krém", checked: false), vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000005", checklistId: "00000000-0000-0000-0000-000000000001", title: "Slnečné okuliare", checked: false), vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000004", checklistId: "00000000-0000-0000-0000-000000000001", title: "Plavky", checked: false), vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000003", checklistId: "00000000-0000-0000-0000-000000000001", title: "Teplé oblečenie na večer", checked: false), vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000002", checklistId: "00000000-0000-0000-0000-000000000001", title: "Lieky", checked: false), vacatuner.ChecklistItem(id: "00000000-0000-0000-0000-000000000001", checklistId: "00000000-0000-0000-0000-000000000001", title: "Pas", checked: true)], "name": "Europa"]

when I call Pantry.pack() on the checklist instance, I stumble upon a crash in JSONWarehouse.swift:

let data = try JSONSerialization.data(withJSONObject: storableDictionary, options: .prettyPrinted)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'
@monday8am
Copy link

the same is happening to me.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSTaggedDate)'

seems to be that a struct containing a Date can't be "packed". My temporal solution is to "pack" an intermediary storage type and not the serialized struct.

@niazoff
Copy link

niazoff commented Feb 12, 2017

Same with me. No clue what to do.

@reinaldoluckman
Copy link

Different data type (a business class that I have), same error.

@rickvdl
Copy link

rickvdl commented Mar 20, 2017

Also happening to me. Log:

2017-03-20 10:14:23.075 GLURooster[10782:3990895] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000010498bd4b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x0000000103fd321e objc_exception_throw + 48
	2   CoreFoundation                      0x00000001049f52b5 +[NSException raise:format:] + 197
	3   Foundation                          0x0000000101e7b964 _writeJSONValue + 668
	4   Foundation                          0x0000000101e7bdb9 ___writeJSONArray_block_invoke + 132
	5   CoreFoundation                      0x00000001049317bf __NSArrayEnumerate + 607
	6   Foundation                          0x0000000101e7babf _writeJSONArray + 330
	7   Foundation                          0x0000000101e7b8e4 _writeJSONValue + 540
	8   Foundation                          0x0000000101ed1232 ___writeJSONObject_block_invoke + 226
	9   CoreFoundation                      0x0000000104912b5c __NSDictionaryEnumerate + 828
	10  Foundation                          0x0000000101ed1026 _writeJSONObject + 430
	11  Foundation                          0x0000000101e7b84d _writeJSONValue + 389
	12  Foundation                          0x0000000101e7bdb9 ___writeJSONArray_block_invoke + 132
	13  CoreFoundation                      0x00000001049317bf __NSArrayEnumerate + 607
	14  Foundation                          0x0000000101e7babf _writeJSONArray + 330
	15  Foundation                          0x0000000101e7b8e4 _writeJSONValue + 540
	16  Foundation                          0x0000000101ed1232 ___writeJSONObject_block_invoke + 226
	17  CoreFoundation                      0x0000000104912b5c __NSDictionaryEnumerate + 828
	18  Foundation                          0x0000000101ed1026 _writeJSONObject + 430
	19  Foundation                          0x0000000101e7b84d _writeJSONValue + 389
	20  Foundation                          0x0000000101e7b674 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
	21  Foundation                          0x0000000101e7b554 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
	22  Pantry                              0x0000000101ba3dd6 _TFC6Pantry13JSONWarehouse5writefTP_7expiresOS_13StorageExpiry_T_ + 838
	23  Pantry                              0x0000000101ba70a1 _TTWC6Pantry13JSONWarehouseS_18WarehouseCacheableS_FS1_5writefTP_7expiresOS_13StorageExpiry_T_ + 81
	24  Pantry                              0x0000000101baeb7b _TZFC6Pantry6Pantry4packuRxS_8StorablerfTGSax_3keySS7expiresOS_13StorageExpiry_T_ + 875
	25  GLURooster                          0x00000001016de56e _TFFC10GLURooster18WeekDataController9fetchDataFT9onSuccessFT_T_9onFailureFSST__T_U_FGSaV20GLURoosterAPIService3Day_T_ + 814
	26  GLURooster                          0x00000001016de9f1 _TPA__TFFC10GLURooster18WeekDataController9fetchDataFT9onSuccessFT_T_9onFailureFSST__T_U_FGSaV20GLURoosterAPIService3Day_T_ + 401
	27  GLURoosterAPIService                0x0000000101e28248 _TFFC20GLURoosterAPIService10APIManager9fetchWeekFT10studentSetVS_10StudentSet10weekNumberGSqSi_9onSuccessFGSaVS_3Day_T_9onFailureFSST__T_U_FV10SwiftyJSON4JSONT_ + 2328
	28  GLURoosterAPIService                0x0000000101e258c1 _TFFC20GLURoosterAPIService10APIManagerP33_0095CE809C71AEE38784D01EBF466CCF3GETFTSS10parametersGSqGVs10DictionarySSSS__9onSuccessFV10SwiftyJSON4JSONT_9onFailureFSST__T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 1505
	29  GLURoosterAPIService                0x0000000101e2885c _TPA__TFFC20GLURoosterAPIService10APIManagerP33_0095CE809C71AEE38784D01EBF466CCF3GETFTSS10parametersGSqGVs10DictionarySSSS__9onSuccessFV10SwiftyJSON4JSONT_9onFailureFSST__T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 124
	30  GLURoosterAPIService                0x0000000101e25dbb _TTRXFo_oGSqV10Foundation4Data_oGSqCSo11URLResponse_oGSqPs5Error____XFdCb_dGSqCSo6NSData_dGSqS1__dGSqCSo7NSError___ + 203
	31  CFNetwork                           0x0000000106e4fccc __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
	32  CFNetwork                           0x0000000106e4f578 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 308
	33  Foundation                          0x0000000101e8b9ad __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
	34  Foundation                          0x0000000101e8b68f -[NSBlockOperation main] + 101
	35  Foundation                          0x0000000101e89d8c -[__NSOperationInternal _start:] + 672
	36  Foundation                          0x0000000101e85ccf __NSOQSchedule_f + 201
	37  libdispatch.dylib                   0x000000010616b0cd _dispatch_client_callout + 8
	38  libdispatch.dylib                   0x0000000106148e17 _dispatch_queue_serial_drain + 236
	39  libdispatch.dylib                   0x0000000106149b4b _dispatch_queue_invoke + 1073
	40  libdispatch.dylib                   0x000000010614c385 _dispatch_root_queue_drain + 720
	41  libdispatch.dylib                   0x000000010614c059 _dispatch_worker_thread3 + 123
	42  libsystem_pthread.dylib             0x000000010651a712 _pthread_wqthread + 1299
	43  libsystem_pthread.dylib             0x000000010651a1ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

@ivanmkc
Copy link

ivanmkc commented Jun 3, 2017

Same. Any updates on this?

@nickoneill
Copy link
Owner

Nope, definitely no time to work on this coming up. I expect there will be no more updates as Swift 4 will provide native de/serialization when it's released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants