Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multidimensional NSArray not mapped #2533

Open
schurtertom opened this issue Mar 19, 2018 · 0 comments
Open

Multidimensional NSArray not mapped #2533

schurtertom opened this issue Mar 19, 2018 · 0 comments

Comments

@schurtertom
Copy link

I have now searched quite a long time but did not find a solution to the following problem:

I would like to map with RestKit my JSON response.
In general this is working but, if I have a multidimensional array with custom Objects the mapping does not work.

this is my JSON structure (this can not be changed):

{"myItems":
    {
        "dataSets": ["current objects"],["past objects"]
        "objectList":[
            [
                {"type":114,"objectId":"Objekt 0","measurement":1277962138,"objectName":"est suspendisse maecenas","street":"lectus cursus in","zipCode":"vitae","city":"primis","period":""},
                {"type":110,"objectId":"Objekt 1","measurement":956814287,"objectName":"quam orci nibh","street":"vel nonummy nec","zipCode":"cursus","city":"pede","period":""}
             ],
             [
                {"type":181,"objectId":"Objekt 2","measurement":1378930412,"objectName":"augue fermentum non","street":"odio arcu vitae","zipCode":"quam","city":"placerat","period":""}
             ]
         ]
     }
}

My mapping looks like this:

@implementation MyItems
- (RKObjectMapping *) getFieldMappings
{
    // setup object mappings
    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[MyItems class]];
    [venueMapping addAttributeMappingsFromDictionary:@{@"dataSets" : @"dataSets"}];
    
     // this is not working...
     RKObjectMapping *newsMapping = [[[ObjectList alloc] init] getFieldMappings];
    [venueMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"objectList" toKeyPath:@"objectList" withMapping:newsMapping]];

    return venueMapping;
}
@end

This is my Object Class

@implementation ObjectList
- (RKObjectMapping *) getFieldMappings
{
    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[ObjectList class]];
    [venueMapping addAttributeMappingsFromDictionary:@{@"type" : @"type", @"objectId" : @"objectId", @"objectName" : @"objectName", @"measurement" : @"measurement", @"street" : @"street", @"zipCode" : @"zipCode", @"city" : @"city", @"period" : @"period"}];

    return venueMapping;
}
@end

For some reason, I have a second JSON call which is working absolutely fine.
Here is the one that works, only difference is that this second call does not contain custom objects just NSInteger...

// this works perfectly fine!!! The consumption is parsed correctly
@implementation ObjectConsumption
- (RKObjectMapping *) getFieldMappings
{
    RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[ObjectConsumption class]];
    [venueMapping addAttributeMappingsFromDictionary:@{@"unit" : @"unit", @"xLabels" : @"xLabels", @"dataSets" : @"dataSets", @"values" : @"values"}];

    return venueMapping;
}
@end

and here is the JSON for the consumption:

{
    "barChartData":{
        "unit":"CHF",
        "dataSets":[["2016 (1)","2016 (2)","2016 (3)","2016 (4)","2016 (5)","2016 (6)","2016 (7)","2016 (8)","2016 (9)","2016 (10)","2016 (11)","2016 (12)"]],
        "values":[[[237,83,249,-258],[151,124,89,-276],[137,134,111,-202],[174,71,79,-265],[117,176,255,-256],[56,166,69,-233],[243,238,185,-136],[56,39,224,-66],[142,130,223,-37],[229,230,177,-179],[249,83,247,-256],[179,292,181,-275]]],
        "xLabels":["Q1","Q2","Q3","Q4","Q5","Q6","Q7","Q8","Q9","Q10","Q11","Q12"]
    },
    "reportType":1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant