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 7885557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:06:09+00:00 2026-06-03T05:06:09+00:00

I’m working with a RestKit framework for one of my projects. It includes an

  • 0

I’m working with a RestKit framework for one of my projects. It includes an example of how to convert JSON objects into a core data graph using object mapping. I’m wandering if the reverse is possible – can a Core Data entity using RestKit be converted back to a JSON representation?

I found RKObjectSerializer class, but I can’t seem to make it work – the serialized object that I get is nil

-(void)doCoreDataToJSONConversion
{
    Article* article = [_articles objectAtIndex:0];
    RKManagedObjectMapping* articleMapping = [RKManagedObjectMapping mappingForClass:[Article class]];
    NSAssert(articleMapping!=nil,@"article mapping is nil!");
    NSLog(@"%@",[article description]);

    RKObjectSerializer* serializer =[RKObjectSerializer serializerWithObject:article mapping:articleMapping];

    NSError* error = nil;
    NSMutableDictionary* serializedObject = [serializer serializedObject:&error];

    if(error!=nil)
    {
        NSLog(@"!!!!! Error: %@",[error localizedDescription]);
    }

    //prints nil
    NSLog(@"Serialized Object: %@", [serializedObject description]);
}

Thank you for your input!

  • 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-03T05:06:10+00:00Added an answer on June 3, 2026 at 5:06 am

    I ended up using these methods to convert core data objects into JSON. To deserialize these objects I need to define a different class of mapping: RKManagedObjectMapping, which is slightly different from the regular object mapping.

    -(void)setupObjectSerializationMapping
    {
        RKObjectManager *objectManager = [RKObjectManager sharedManager ] ;
        RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Article class]];
    
        [mapping mapAttributes:@"articleID", @"title", @"body", nil];
    
        //********************************    
    
        RKObjectMapping *imageMapping = [RKObjectMapping mappingForClass:[EventImage class]];
    
        [imageMapping mapAttributes:@"createDate", @"localFilePath", nil];
        [objectManager.mappingProvider addObjectMapping:imageMapping];
        [objectManager.mappingProvider setSerializationMapping:[imageMapping inverseMapping] forClass:[EventImage class]];
        [objectManager.mappingProvider setMapping:imageMapping forKeyPath:@"eventImages"];
    
        //********************************    
    
        RKObjectMapping *eventMapping = [RKObjectMapping mappingForClass:[Event class]];
    
        [eventMapping mapAttributes:@"createDate", @"note", nil];
        [eventMapping mapRelationship:@"eventImages" withMapping:imageMapping];
    
        [objectManager.mappingProvider addObjectMapping:eventMapping];
        [objectManager.mappingProvider setSerializationMapping:[eventMapping inverseMapping] forClass:[Event class]];
        [objectManager.mappingProvider setMapping:eventMapping forKeyPath:@"events"];
    
        //******************************** 
        //setup App user mapping
        RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[AppUserSubclass class]];
    
        [userMapping mapAttributes:@"userID",@"firstName", @"lastName",@"localDataFilepath", nil];
        [userMapping mapRelationship:@"events" withMapping:eventMapping];
        [objectManager.mappingProvider addObjectMapping:userMapping];
        [objectManager.mappingProvider setSerializationMapping:[userMapping inverseMapping] forClass:[AppUserSubclass class]];
        [objectManager.mappingProvider setMapping:userMapping forKeyPath:@"appUser"];
    
    
    
    }
    
    -(NSString*)generateLocalJSONData
    {
    
        NSString* folderPath = [self dataFolderPath];
        // remember what the file was called. This will not include the documents directory and will be the same on all machines.
        NSString* localFileName = [self fileName];
    
        NSString* dataFile = [self fullDocumentsFilePath];
        self.localDataFilepath = dataFile;
    
        NSAssert(self.localDataFilepath!=nil,@"failed to save local data path");
        //********************************
    
    
        NSError* error = nil;
    
        //app user subclass is the same as AppUser, but is used to differentiate between file based mapping and core data mapping
        RKObjectMapping *serMap = [[[RKObjectManager sharedManager] mappingProvider] serializationMappingForClass:[AppUserSubclass class]];
        NSDictionary *d = [[RKObjectSerializer serializerWithObject:self mapping:serMap] serializedObject:&error];
    
    
        if(error!=nil)
        {
            NSLog(@"!!!!! Error: %@",[error localizedDescription]);
        }
    
    
        NSString* dataContents = [d JSONString];
        BOOL success =  [dataContents writeToFile:dataFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
        if(!success)
        {
            NSLog(@"Error writing to data file!");
        }
        [[AppUser managedObjectContext] save:nil];
    
        return dataFile;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.