ios - Ignore nil properties when serializing JSON using RestKit -
i have class:
@interface moviestatus : nsobject @property (nonatomic, strong) nsnumber* seen; @property (nonatomic, strong) nsnumber* watchlist; @end
where both properties represent optional nullable boolean values. i'm sending object server using restkit through rkobjectmanager
, created appropriate mapping. i'm unable skip property post data when serializing object.
for example, code:
rklogconfigurebyname("*", rklogleveltrace); rkobjectmanager* manager = [rkobjectmanager managerwithbaseurl:[nsurl urlwithstring:@"http://www.example.com/v1"]]; manager.requestserializationmimetype = rkmimetypejson; rkobjectmapping* requestmapping = [rkobjectmapping requestmapping]; [requestmapping addattributemappingsfromarray:@[@"seen", @"watchlist"]]; rkrequestdescriptor* requestdescriptor = [rkrequestdescriptor requestdescriptorwithmapping:requestmapping objectclass:[moviestatus class] rootkeypath:nil method:rkrequestmethodpost]; [manager addrequestdescriptor:requestdescriptor]; rkroute* route = [rkroute routewithclass:[moviestatus class] pathpattern:@"status" method:rkrequestmethodpost]; [manager.router.routeset addroute:route]; moviestatus* status = [[moviestatus alloc] init]; status.seen = @(yes); [manager postobject:status path:nil parameters:nil success:nil failure:nil];
is sending json:
{ "seen": true, "watchlist": null }
where i'd send:
{ "seen": true }
can point me out how can achieve it?
i solved setting assignsdefaultvalueformissingattributes
of mapping no
:
requestmapping.assignsdefaultvalueformissingattributes = no;
now json request doesn't contain null
values.
Comments
Post a Comment