Realm-JSON
Realm-JSON copied to clipboard
Outbound mapping with keypath into single key
Hi. Please, does Realm+JSON somehow supports outbound object mapping from RLMObject into JSON from keypath object.property into key property?
I have object scheme such like:
@interface MyObject
@property NSString * attr1;
@property NSString * attr2;
@property MySubobject * subobject;
@end
@interface MySubobject
@property NSString * attr3;
@property NSNumber<RLMInt> * attr4;
@end
In one specific case I need to create JSON with structure that attr1, attr2, attr3 and attr4 would be on the same level, therefore something like:
+ (NSDictionary *)JSONOutboundMappingDictionary {
return @{
@"attr1" : @"attr1",
@"attr2" : @"attr2",
@"subobject.attr3" : @"attr3",
@"subobject.attr4" : @"attr4"
};
}
So far it keeps crashing and I can't figure out how to achieve such effect without removing MySubobject ale moving all it's attributes into main object (or creating JSON manually from self-created NSDictionary). Is it even possible with Realm+JSON? I noticed inverse case from JSON keypath to single key in RLMObject is allowed. In advance thanks for any answer.
I tried achieving the same thing, so finally I have made a modification: introduced JSON preprocessing method, in which you can join your values. https://github.com/matthewcheok/Realm-JSON/pull/86 is the pull request for that.