RestKit/RestKit — Issue #498: CoreData Transformable data type causes NSNulls in object
Author: PDay9
Created: 2012-01-09 23:12:52+00:00
State: open

I created several NSManagedObjects that have Transformable attributes. Whenever I receive JSON responses back that specify 'null' for the value of one of those attributes, that object's value gets set to [NSNull null].

Normally, when [RKObjectMappingOperation applyAttributeMappings:withValue:] is called, it checks the source and destination types of the data and does any necessary transformations as needed. But when that specific attribute is marked as Transformable, the RKObjectPropertyInspector can't find that property and thus doesn't know to try and do any basic transformations, such has converting NSNull to nil. (The dictionary returned by [RKObjectPropertyInspector propertyNamesAndTypesForClass:] simply doesn't list any attribute that was listed as Transformable).

Two work arounds I've done locally, is to either override [RKObjectPropertyInspector propertyNamesAndTypesForClass:] to use the NSEntityDescription et al, when the specified class inherits from NSManagedObject, or to edit [RKObjectMappingOperation applyAttributeMapping:withValue:] to always transform NSNull to nil regardless of the data types involved.