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

Cannot decode object to int id #287

Open
parkesb opened this issue Apr 30, 2018 · 0 comments
Open

Cannot decode object to int id #287

parkesb opened this issue Apr 30, 2018 · 0 comments

Comments

@parkesb
Copy link

parkesb commented Apr 30, 2018

If using propertyConverters to convert an id to an object when encoding. Upon decoding, the convert does not replace the object with an ID but instead replaces it with an empty dictionary.

For example:

    var object_id : Object = Object()
...
    key: "object_id"
    , decodeConverter: {
        if let obj = ObjectsCollection.getById($0 as! Int) {
            self.object_id = obj
        }
    }
    , encodeConverter: {
        return self.object_id.id
    }

In EVReflection:

                    // Convert the Any value to a NSObject value
                    var (unboxedValue, valueType, isObject) = valueForAny(theObject, key: originalKey, anyValue: value, conversionOptions: conversionOptions, isCachable: isCachable, parents: parents)

                    if let v = value as? EVCustomReflectable {
                        unboxedValue = v.toCodableValue() as AnyObject
                        valueType = "String"
                        isObject = false
                    }

                    if conversionOptions.contains(.Encoding), let ro = theObject as? EVReflectable {
                        unboxedValue = ro.encodePropertyValue(value: unboxedValue, key: originalKey) as AnyObject
                    }

isObject is set to true (because it's an object) and then below:

                    if isObject {
                        if let obj = unboxedValue as? EVReflectable {
                            if let json = obj.customConverter() {
                                unboxedValue = json as AnyObject
                            } else {
                                // sub objects will be added as a dictionary itself.
                                let (dict, _) = toDictionary(unboxedValue as? NSObject ?? NSObject(), conversionOptions: conversionOptions, isCachable: isCachable, parents: parents)
                                unboxedValue = dict                                
                            }
                        } else {
                            // sub objects will be added as a dictionary itself.
                            let (dict, _) = toDictionary(unboxedValue as? NSObject ?? NSObject(), conversionOptions: conversionOptions, isCachable: isCachable, parents: parents)
                            unboxedValue = dict
                        }
                    } else if let array = unboxedValue as? [NSObject] {

unboxedValue gets set to an empty dict rather then being set as a value further down

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

1 participant