Closed victorjussiani closed 9 years ago
I'll get rid of that exception as mappingProvider is not always necessary Here is a fix, let me know if it resolves the issue.
ObjectMapper.sharedInstance().mappingProvider = InCodeMappingProvider()
Thank you for the quick response!
When I added the MappingProvider he ask for InstanceProvider, so I added the following line and everything worked normally.
ObjectMapper.sharedInstance().instanceProvider = ObjectInstanceProvider();
I would like to take to take a doubt, I have the following JSON:
{"event": "connect", "data": {"soid": "_ w0_8000_0_ASfNBRdLv12uNUB9AABL", "appName": "app"}, "cid": 1}
As you can see I have a json within another json, the first layer of the JSON I deserialize an object, however the second JSON "data" I would like to deserializes it then because this can be different types, so I need keep it into a NSDictionary.
For this I created the following object to represent this json:
import Foundation
@objc public class SocketMessage: NSObject {
var event: NSString ?;
var cid: NSNumber ?;
var data: NSDictionary? ;
}
However when he deserialize the object to NSDictionary property is null, you could help me with this problem?
I think you are using the version in cocoapods which is old (Doesn't support swift). Use the version from github instead.
Swift uses module name as part of class names and therefore OCMapper should be in the same module as the models you are trying to map.
Add the source folder directly into your project. Also the line of code you have there is no longer needed (setting ObjectInstanceProvider), that's done by default in the latest version
Will fix it on the next version so that the module name can be passed to OCMapper, and will submit a new version to cocoapods
I changed the version, however the error still persists, the property "data" is null;
aaah I see, it won't automatically map it as dictionary you need to write mapping for that
inCodeMappingProvider.mapFromDictionaryKey("data", toPropertyKey:"data", forClass: SocketMessage.self) {
// don't try to map the node
return $0
}
I did the same as you said,
var inCodeMappingProvider: InCodeMappingProvider = InCodeMappingProvider();
inCodeMappingProvider.mapFromDictionaryKey("data", toPropertyKey:"data", forClass: SocketMessage.self);
ObjectMapper.sharedInstance().mappingProvider = inCodeMappingProvider;
However keeps coming null.
That's not the same, you are not using dataTransformers
inCodeMappingProvider.mapFromDictionaryKey("data", toPropertyKey:"data", forClass: SocketMessage.self) { return $0 }
Sorry friend, I was making a mess, now worked perfectly.
Hopefully to update the version in CocoaPods.
Thank you very much
Great Will update the CocoaPods version soon
Hello,
could you help me, when I try to run the following command
it returns the following error:
I'm forgetting to do something?