objective c - RestKit mapping for org.joda.time.Interval obj -
i have working part mapping simple json response. here how like:
rkobjectmapping *eventmapping = [event responsemapping]; rkresponsedescriptor *listeventsresponsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:eventmapping method:rkrequestmethodget pathpattern:nil keypath:nil statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)]; [objectmanager addresponsedescriptor:listeventsresponsedescriptor];
and of course event class (dto)
#import <foundation/foundation.h> #import <restkit/restkit.h> @interface event : nsobject @property (nonatomic, strong) nsstring *id; @property (nonatomic, strong) nsstring *title; @property (nonatomic, strong) nsstring *detail; @property (nonatomic, strong) nsstring *image; + (rkobjectmapping *) responsemapping; @end @implementation event + (nsdictionary *) elementtopropertymappings { return @{ @"id": @"id", @"title": @"title", @"detail": @"detail", @"image": @"image", }; } + (rkobjectmapping *) responsemapping { // create object mapping. rkobjectmapping *mapping = [rkobjectmapping mappingforclass:[event class]]; [mapping addattributemappingsfromdictionary:[event elementtopropertymappings]]; return mapping; } @end
so, way allows me working next response (processed field in bottom of server response):
( { dateinterval = { afternow = 0; beforenow = 1; chronology = { zone = { fixed = 0; id = "europe/kiev"; uncachedzone = { cachable = 1; fixed = 0; id = "europe/kiev"; }; }; }; end = { afternow = 0; beforenow = 1; centuryofera = 20; chronology = { zone = { fixed = 0; id = "europe/kiev"; uncachedzone = { cachable = 1; fixed = 0; id = "europe/kiev"; }; }; }; dayofmonth = 12; dayofweek = 4; dayofyear = 71; equalnow = 0; era = 1; hourofday = 13; millis = 1426160220000; millisofday = 49020000; millisofsecond = 0; minuteofday = 817; minuteofhour = 37; monthofyear = 3; secondofday = 49020; secondofminute = 0; weekofweekyear = 11; weekyear = 2015; year = 2015; yearofcentury = 15; yearofera = 2015; zone = { fixed = 0; id = "europe/kiev"; uncachedzone = { cachable = 1; fixed = 0; id = "europe/kiev"; }; }; }; endmillis = 1426160220000; start = { afternow = 0; beforenow = 1; centuryofera = 20; chronology = { zone = { fixed = 0; id = "europe/kiev"; uncachedzone = { cachable = 1; fixed = 0; id = "europe/kiev"; }; }; }; dayofmonth = 12; dayofweek = 4; dayofyear = 71; equalnow = 0; era = 1; hourofday = 13; millis = 1426160160000; millisofday = 48960000; millisofsecond = 0; minuteofday = 816; minuteofhour = 36; monthofyear = 3; secondofday = 48960; secondofminute = 0; weekofweekyear = 11; weekyear = 2015; year = 2015; yearofcentury = 15; yearofera = 2015; zone = { fixed = 0; id = "europe/kiev"; uncachedzone = { cachable = 1; fixed = 0; id = "europe/kiev"; }; }; }; startmillis = 1426160160000; }; detail = "\"i know cannot count beyond ten, tell you. hold 2 hands. on both of them have altogether ten fingers , thumbs. well. take grain of sand—you hold it, hoo-hoo.\" dropped grain of sand lad's"; id = 14; image = "6f655fd8-ac0d-454f-8b8d-5c93eab34030.png"; new = 0; title = "i know you"; }, { ...
most of server's response regarding date interval. json created java spring, on field jodatime interval.
question: how can 2 nsdate property fields json?
create class myrestkitjodatimemodel
(or number of classes) matches json structure , can use restkit it. use data (you use milliseconds) , create nsdate
it.
nsdate datefromjson = [nsdate datewithtimeintervalsince1970:(nstimeinterval)[myrestkitjodatimemodel millis]/1000]];
with myrestkitjodatimemodel myrestkitjodatimemodel
containing data json.
this assumes have reasons using restkit, such lots of other classes match well. on other hand, if is data receive using restkit make life more difficult easier.
Comments
Post a Comment