Closed eliezer-ferra closed 6 years ago
Are you using EVReflection in a framework? Are the class definitions in another bundle than the main bundle? If so, then you have to make EVReflection aware that it should also look for class definitions in another bundle. You could do that by calling the following function once at startup:
EVReflection.setBundleIdentifier(Device.self)
I added a test for your issue and the serialization / deserialization works ok:
https://github.com/evermeer/EVReflection/blob/master/UnitTests/EVReflectionTests/EVReflectionIssue285.swift#L29
Yes, I was using it in a framework. I made the suggested chance and it worked.
Now I have a question: if both classes were in the framework and not in the main bundle, how come the Customer class was loaded successfully but the Device wasn't?
Good question...
The moment you do the:
return Customer(json: jsonData)
It uses the initializer defined in EVObject. So you are using standard code for initializing that class. It does not need to be created.
Your Customer object has an array of Device object. On initialization that array does exist, but the Device objects that goes in that array do not exist. There is no generic Swift code for creating instances for an array.
With the Mirror command I only get that it's of type Swift.Array
I do have a planned update where I keep a reference to the parent object and pass it on to the createClass function so that it could get the bundle from the parent object and use that. But for now you have to use the setBundleIdentifier.
Got it! Thank you so much for you help. Great framework btw.
Hi I have two clases (Customer & Device) that extend EVObject. The Customer class has a property of type Device.
I'm converting the Customer object to JSON String and later that JSON String converting it back to the Customer object.
When initializing the Customer object from the JSON string, all the properties from the object are loaded except the devices property. The library throwing this error "Could not create an instance for type Device".