Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:12:53+00:00 2026-06-13T05:12:53+00:00

When using Restkit to send an object back to the server, I’m having a

  • 0

When using Restkit to send an object back to the server, I’m having a problem with a nested array of sub objects ONLY when I attach an image.

This is the mapping summary I’m using for all requests:

// mapping for post tag details
tagMapping = [RKObjectMapping mappingForClass:[TagObject class]];
[tagMapping mapKeyPath:@"id" toAttribute:@"tagId"];
[tagMapping mapKeyPath:@"name" toAttribute:@"tagName"];
[[RKObjectManager sharedManager].mappingProvider setMapping:tagMapping forKeyPath:@"tags"];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[tagMapping inverseMapping] forClass:[TagObject class]];

// mapping for posts
poastMapping = [[RKObjectMapping alloc] init];
poastMapping = [RKObjectMapping mappingForClass:[PoastObject class]];
[poastMapping mapKeyPath:@"id" toAttribute:@"poastId"];
[poastMapping mapKeyPath:@"user_id" toAttribute:@"userId"];
[poastMapping mapKeyPath:@"blurb" toAttribute:@"blurb"];
[poastMapping mapKeyPath:@"photo" toAttribute:@"photo"];
[poastMapping mapKeyPath:@"avatar" toAttribute:@"avatar"];
[poastMapping mapKeyPath:@"date_created" toAttribute:@"dateCreated"];
[poastMapping mapKeyPath:@"firstname" toAttribute:@"firstName"];
[poastMapping mapKeyPath:@"lastname" toAttribute:@"lastName"];
[poastMapping mapKeyPath:@"session" toAttribute:@"session"];
[poastMapping mapKeyPath:@"device" toAttribute:@"device"];
[poastMapping mapKeyPath:@"comments" toAttribute:@"iComments"];
[poastMapping mapKeyPath:@"commentcount" toAttribute:@"commentCount"];
[poastMapping mapKeyPath:@"pointcount" toAttribute:@"pointCount"];
[poastMapping mapKeyPath:@"heartcount" toAttribute:@"heartCount"];
[poastMapping mapKeyPath:@"postcount" toAttribute:@"postCount"];
[poastMapping mapKeyPath:@"hearted" toAttribute:@"hearted"];
[poastMapping mapKeyPath:@"total" toAttribute:@"total"];
[poastMapping mapKeyPath:@"tags" toRelationship:@"tags" withMapping:tagMapping];

[[RKObjectManager sharedManager].mappingProvider addObjectMapping:poastMapping];
[[RKObjectManager sharedManager].mappingProvider setMapping:poastMapping forKeyPath:@"posts"];
[[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[poastMapping inverseMapping] forClass:[PoastObject class]];

And this is the block that sends the request (note that certain changes are only occurring when an image is attached)

[[RKObjectManager sharedManager] sendObject:obj toResourcePath:@"/posts/submit" usingBlock:^(RKObjectLoader *loader) {
        loader.targetObject = nil;
        loader.delegate = self;
        loader.method = RKRequestMethodPOST;

        if([obj image]){
            RKObjectMapping* serializationMapping = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[PoastObject class]];
            NSError* error = nil;
            NSDictionary* dictionary = [[RKObjectSerializer serializerWithObject:obj mapping:serializationMapping] serializedObject:&error];
            RKParams* params = [RKParams paramsWithDictionary:dictionary];
            NSData* imageData =  UIImagePNGRepresentation([obj image]);
            [params setData:imageData MIMEType:@"image/png" forParam:@"image"];
            loader.params = params;
        }
    }];

When sending a request without the image, the ‘tags’ array arrives in PHP as type ‘array’ as expected. However, when sending a request with the image, the tags array comes in as a type ‘string’ and looks like the following:

(
{
id = 2;
name = Science;
},
{
id = 4;
name = Academics;
} )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:12:55+00:00Added an answer on June 13, 2026 at 5:12 am

    The only way I could find around this was to simply add the nested array again as a JSON encoded string for that parameter and then json_decode on the server side. Still not sure why this bug is happening.

    Updated Code:

    [[RKObjectManager sharedManager] sendObject:obj toResourcePath:@"/posts/submit" usingBlock:^(RKObjectLoader *loader) {
    
        loader.targetObject = nil;
        loader.delegate = self;
        loader.method = RKRequestMethodPOST;
    
        RKObjectMapping* serializationMapping = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[PoastObject class]];
        NSError* error = nil;
        NSDictionary* dictionary = [[RKObjectSerializer serializerWithObject:obj mapping:serializationMapping] serializedObject:&error];
    
        // grab the tag array
        NSArray *tags = [dictionary objectForKey:@"tags"];
        NSString *tagData = [tags JSONString];
    
        RKParams* params = [RKParams paramsWithDictionary:dictionary];
    
        // assign tags as a value in the parameters manually
        [params setValue:tagData forParam:@"tags"];
    
        // add image if it exists
        if([obj imageV]){
            NSData* imageData =  UIImageJPEGRepresentation([obj imageV], 0.75);
            [params setData:imageData MIMEType:@"image/jpg" forParam:@"image"];
        }
    
        loader.params = params;
    
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using RestKit to post an object to a server or to get it.
I am having trouble mapping a JSON response to objects using RestKit and Objective-C.
Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
I have a small app using RestKit with a Sinatra-backed server. When I post
I need to send a JSON request to a REST service. I'm using Restkit
Im using Restkit OM2 to take in a json and map to objects on
I'm trying to POST an object using Restkit, but when I set some extra
I'm using RestKit to grab objects from my RoR service and using CoreData to
I'm using restkit trying to serialize an object after I do a PUT request,
I am trying to map and store a response json data using restkit object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.