Skip to content

Instantly share code, notes, and snippets.

@ryanmaxwell
Last active December 23, 2015 01:19
Show Gist options
  • Save ryanmaxwell/6559086 to your computer and use it in GitHub Desktop.
Save ryanmaxwell/6559086 to your computer and use it in GitHub Desktop.
Mantle JSON Mapping Example
[{
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"userId": "156",
"equipmentTypeId": 1,
"mapId": 1,
"yCoordinate": 85,
"equipmentModelId": 1,
"departmentId": 1,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 135,
"unitOfMeasure": "MM",
"equipmentId": 1,
"equipmentNumber": "211",
"equipmentModelName": "SP3500",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Seth",
"lastName": "Brigham",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "SP",
"heading": 125
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"yCoordinate": 95,
"utcTimestamp": 1379136985181.3801,
"xCoordinate": 345,
"equipmentNumber": "217",
"userId": "156",
"equipmentId": 2,
"unitOfMeasure": "MM",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeId": 1,
"status": "Active",
"equipmentTypeName": "SP",
"equipmentModelName": "SP3500",
"mapVersion": 1,
"zCoordinate": 93.0,
"heading": -135,
"mapId": 1,
"equipmentModelId": 1
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"userId": "156",
"equipmentTypeId": 1,
"mapId": 1,
"yCoordinate": 105,
"equipmentModelId": 1,
"departmentId": 1,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 555,
"unitOfMeasure": "MM",
"equipmentId": 3,
"equipmentNumber": "222",
"equipmentModelName": "SP3500",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Patrick",
"lastName": "Truster",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "SP",
"heading": -35
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"yCoordinate": 475,
"utcTimestamp": 1379136985181.3801,
"xCoordinate": 405,
"equipmentNumber": "226",
"userId": "156",
"equipmentId": 4,
"unitOfMeasure": "MM",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeId": 1,
"status": "Active",
"equipmentTypeName": "SP",
"equipmentModelName": "SP3500",
"mapVersion": 1,
"zCoordinate": 93.0,
"heading": 65,
"mapId": 1,
"equipmentModelId": 1
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"userId": "156",
"equipmentTypeId": 2,
"mapId": 1,
"yCoordinate": 485,
"equipmentModelId": 3,
"departmentId": 1,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 615,
"unitOfMeasure": "MM",
"equipmentId": 5,
"equipmentNumber": "290",
"equipmentModelName": "TSP7000",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Jim",
"lastName": "Post",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "TSP",
"heading": 165
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"userId": "156",
"equipmentTypeId": 2,
"mapId": 1,
"yCoordinate": 495,
"equipmentModelId": 2,
"departmentId": 1,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 825,
"unitOfMeasure": "MM",
"equipmentId": 6,
"equipmentNumber": "297",
"equipmentModelName": "TSP6000",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Adam",
"lastName": "Garman",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "TSP",
"heading": -95
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 1,
"userId": "156",
"equipmentTypeId": 2,
"mapId": 1,
"yCoordinate": 775,
"equipmentModelId": 2,
"departmentId": 1,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 765,
"unitOfMeasure": "MM",
"equipmentId": 7,
"equipmentNumber": "299",
"equipmentModelName": "TSP6000",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Michael",
"lastName": "Krieg",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "TSP",
"heading": 5
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 2,
"userId": "156",
"equipmentTypeId": 3,
"mapId": 1,
"yCoordinate": 875,
"equipmentModelId": 4,
"departmentId": 2,
"zCoordinate": 93.0,
"status": "Active",
"xCoordinate": 885,
"unitOfMeasure": "MM",
"equipmentId": 8,
"equipmentNumber": "234",
"equipmentModelName": "TSP6000",
"mapVersion": 1,
"utcTimestamp": 1379136985181.3801,
"firstName": "Harry",
"lastName": "Brown",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeName": "TSP",
"heading": 105
}, {
"sector": 0,
"macAddress": "000B6B245A67",
"facilityId": 2,
"yCoordinate": 885,
"utcTimestamp": 1379136985181.3801,
"xCoordinate": 1095,
"equipmentNumber": "235",
"userId": "156",
"equipmentId": 9,
"unitOfMeasure": "MM",
"moduleDate": "08/07/13 09:04:48 PM EDT",
"equipmentTypeId": 3,
"status": "Active",
"equipmentTypeName": "TSP",
"equipmentModelName": "TSP6000",
"mapVersion": 1,
"zCoordinate": 93.0,
"heading": -155,
"mapId": 1,
"equipmentModelId": 4
}]
@interface TXLocation : MTLModel <MTLJSONSerializing>
@property (strong, nonatomic, readonly) NSString *status;
@property (strong, nonatomic, readonly) NSNumber *sector;
@property (strong, nonatomic, readonly) NSString *macAddress;
@property (strong, nonatomic, readonly) NSNumber *facilityId;
@property (strong, nonatomic, readonly) NSNumber *departmentId;
@property (strong, nonatomic, readonly) NSNumber *mapId;
@property (strong, nonatomic, readonly) NSNumber *mapVersion;
@property (strong, nonatomic, readonly) NSNumber *xCoordinate;
@property (strong, nonatomic, readonly) NSNumber *yCoordinate;
@property (strong, nonatomic, readonly) NSNumber *zCoordinate;
@property (strong, nonatomic, readonly) NSNumber *heading;
@property (strong, nonatomic, readonly) NSString *unitOfMeasure;
@property (strong, nonatomic, readonly) NSNumber *equipmentId;
@property (strong, nonatomic, readonly) NSNumber *equipmentTypeId;
@property (strong, nonatomic, readonly) NSString *equipmentTypeName;
@property (strong, nonatomic, readonly) NSNumber *equipmentModelId;
@property (strong, nonatomic, readonly) NSString *equipmentNumber;
@property (strong, nonatomic, readonly) NSString *equipmentModelName;
@property (strong, nonatomic, readonly) NSNumber *shiftId;
@property (strong, nonatomic, readonly) NSString *userId;
@property (strong, nonatomic, readonly) NSString *firstName;
@property (strong, nonatomic, readonly) NSString *lastName;
@property (strong, nonatomic, readonly) NSString *fullName;
@property (strong, nonatomic, readonly) NSNumber *utcTimestamp;
@property (strong, nonatomic, readonly) NSDate *moduleDate;
@property (strong, nonatomic, readonly) NSString *timeZone;
@end
#import "TXLocation.h"
@implementation TXLocation
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{};
}
- (NSString *)fullName {
if (self.firstName.length && self.lastName.length) {
return [NSString stringWithFormat:@"%@ %@", self.firstName, self.lastName];
} else if (self.firstName.length) {
return self.firstName;
} else if (self.lastName.length) {
return self.lastName;
}
return nil;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment