evermeer / EVReflection

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Other
965 stars 119 forks source link

Dictionaries broken? #52

Closed shexbeer closed 8 years ago

shexbeer commented 8 years ago

I really love EVReflection. But while testing the library i discovered a major problem for me. I would like to get this result:

{
    "dict": {
        "foo": "bar"
    }
}

and used this code in the playground

import UIKit
import EVReflection

class User : EVObject {
    var dict : [String:String] = ["t":"bar"]
    required init() {
    }
}

let json = User().toJsonString()

But all i get is this uncaught exception:

2016-03-05 10:34:08.599 MyPlayground[51394:2089709] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_TtGCSs29_NativeDictionaryStorageOwnerSSSS_ 0x7fc0a36022d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key foo.'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107863e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000109133deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107863aa9 -[NSException raise] + 9
    3   Foundation                          0x00000001072e69bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
    4   EVReflection                        0x0000000115e8a7fe _TZFC12EVReflection12EVReflectionP33_B5E655244C8CE8B4EE02BAF482E9510D37convertDictionaryForJsonSerializationfMS0_FCSo12NSDictionaryS1_ + 398
    5   EVReflection                        0x0000000115e9943d _TZFC12EVReflection12EVReflectionP33_B5E655244C8CE8B4EE02BAF482E9510D32convertValueForJsonSerializationfMS0_FPSs9AnyObject_PS1__ + 1533
    6   EVReflection                        0x0000000115e8a762 _TZFC12EVReflection12EVReflectionP33_B5E655244C8CE8B4EE02BAF482E9510D37convertDictionaryForJsonSerializationfMS0_FCSo12NSDictionaryS1_ + 242
    7   EVReflection                        0x0000000115e8a380 _TZFC12EVReflection12EVReflection12toJsonStringfMS0_FTCSo8NSObject17performKeyCleanupSb_SS + 240
    8   EVReflection                        0x0000000115e79487 _TFC12EVReflection8EVObject12toJsonStringfS0_FTSb_SS + 71
    9   ???                                 0x00000001129050c7 0x0 + 4606415047
    10  MyPlayground                        0x00000001071b1840 main + 0
    11  MyPlayground                        0x00000001071b4711 _TTRXFo__dT__XFo_iT__iT__ + 17
    12  MyPlayground                        0x00000001071b41a1 _TPA__TTRXFo__dT__XFo_iT__iT__ + 81
    13  MyPlayground                        0x00000001071b4740 _TTRXFo_iT__iT__XFo__dT__ + 32
    14  MyPlayground                        0x00000001071b4777 _TTRXFo__dT__XFdCb__dT__ + 39
    15  CoreFoundation                      0x000000010778fa1c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    16  CoreFoundation                      0x00000001077856a5 __CFRunLoopDoBlocks + 341
    17  CoreFoundation                      0x0000000107784e02 __CFRunLoopRun + 850
    18  CoreFoundation                      0x0000000107784828 CFRunLoopRunSpecific + 488
    19  GraphicsServices                    0x000000010e265ad2 GSEventRunModal + 161
    20  UIKit                               0x0000000107c10610 UIApplicationMain + 171
    21  MyPlayground                        0x00000001071b1d8a main + 1354
    22  libdyld.dylib                       0x000000010a98f92d start + 1
    23  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Am i missing something here?

evermeer commented 8 years ago

I just pushed fix for this to GitHub and Cocoapods as release 2.19.2 You can find a unit test for this at: https://github.com/evermeer/EVReflection/blob/1d9ab8edf09f47e997729c99ad0510724513fccc/EVReflection/EVReflectionTests/EVReflectionTests.swift#L235-L235