1

Please skip this part to UPDATE 3.

Environment: iOS7.1, MagicalRecord, Restkit, Mogenerator

The required JSON form looks like this:

{"amount":[10,20,50]}  (set of TSNDecimal's in TSNTagAmountRequest)

The following entities are involved in the request:

@interface TSNTagAmountRequest: NSManagedObject
@property (nonatomic, strong) NSSet *amount;
@end

where the set of amounts is set of TSNDecimal's:

@interface TSNDecimal: NSManagedObject
@property (nonatomic, strong) NSDecimalNumber* number;
@end

The decimal number with name number is a helper.

RKObjectMapping for TSNDecimal:

RKEntityMapping *decimalMapping = [RKEntityMapping 
                                       mappingForEntityForName:@"TSNDecimal" 
                                          inManagedObjectStore:managedObjectStore];

// map the value in JSON directly to the helper "number"
[decimalMapping addPropertyMapping:
    [RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"number"]];

The previous line is the code I would expect to deserialize correctly "amount":[10,20,50] to three TSNDecimal's, respectively to their number attributes (it works) and also it should serialize properly from set of TSNDecimal (via number) to JSON: "amount":[10,20..] It works when parsing response but not for the request.

The rest is the relationship mappings:

RKPropertyMapping* decimalPropertyMappingAmount =
    [RKRelationshipMapping relationshipMappingFromKeyPath:@"amount"
                                                toKeyPath:@"amount"
                                              withMapping:decimalMapping];

(I also tried FromKeyPath:@"amount.number" toKeyPath:@"amount" but an exception is being raised because of passing an incorrect path to KVC ([self.object valueForKey:key]))

Finally I have defined the relationship between TSNTagAmountRequest and TSNDecimal: tagAmountRequestMapping = [RKObjectMapping requestMapping]; [tagAmountRequestMapping addPropertyMapping:decimalPropertyMappingAmount];

and add the descriptor to the RK manager:

requestDescriptor = [RKRequestDescriptor 
            requestDescriptorWithMapping:tagAmountRequestMapping
                             objectClass:[TSNTagAmountRequest class]
                             rootKeyPath:nil
                                  method:RKRequestMethodPOST];

[_rkManager addRequestDescriptor:requestDescriptor];

The issue is that there is an exception raised in NSJSONSerialization dataWithJSONObject:optionserror: obviously because the TSNDecimal is not translated from TSNDecimal.number to NSDecimalNumber which NSJSONSerialization understands.

Exception: Invalid type in JSON write (TSNDecimal) because the data coming in dataFromObject in RKNSJSONSerialization contains TSNDecimal objects created by RKObjectMappingOperationDataSource (not RKManagedObjectMappingOperationDataSource)

{
    amount =     (
        "<TSNDecimal: 0xc1d0bf0> (entity: (null); id: (null) ; data: {\n})",
        "<TSNDecimal: 0x11543080> (entity: (null); id: (null) ; data: {\n})"
    );
}

it should be NSDecimalNumber instead of TSNDecimal I guess.

In summary I was expecting the code

[decimalMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"number"]];

does its job and translates "number" back to nil (that is, to unnamed item in the collection) but it does not work this way. There is this example in the section Mapping Values without Key Paths but I am confused by using [RKResponseDescriptor responseDescriptorWithMapping: if I want to compose the JSON body. Parsing from the response is working well with

[decimalMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"number"]];
RKPropertyMapping* decimalPropertyMappingAmount =
    [RKRelationshipMapping relationshipMappingFromKeyPath:@"amount"
                                                toKeyPath:@"amount"
                                              withMapping:decimalMapping];

why not for request?

The issue I see there is CoreData: error: Failed to call designated initializer on NSManagedObject class 'TSNDecimal'

The core data objects are initialized with

TSNTagAmountRequest* request = [TSNTagAmountRequest requestWithModel:self];    


TSNDecimal* decimalEntity = nil;

for(NSDecimalNumber* number in amount) {

    decimalEntity = [TSNDecimal MR_createEntity];
    decimalEntity.number = number;
    [request addAmountObject:decimalEntity];
}

Here is the log:

    D restkit.object_mapping:RKMappingOperation.m:860 Starting mapping operation...
    T restkit.object_mapping:RKMappingOperation.m:861 Performing mapping operation: <RKMappingOperation 0x9681ca0> for '__NSDictionaryM' object. Mapping values from object <TSNTagAmountRequest: 0xf7b8c90> (entity: TSNTagAmountRequest; id: 0xf784700 <x-coredata:///TSNTagAmountRequest/tB2DF8887-7E6C-420F-998A-D250751E5CED164> ; data: {
                                                                                                                                                                                                              amount =     (
                                                                                                                                                                                                                            "0x9664220 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED165>",
                                                                                                                                                                                                                            "0x9616390 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED166>"
                                                                                                                                                                                                                            );
                                                                                                                                                                                                              }) ((null)) to object {
    } with object mapping (null)
    D restkit.object_mapping:RKMappingOperation.m:641 Mapping one to many relationship value at keyPath 'amount' to 'amount'
    CoreData: error: Failed to call designated initializer on NSManagedObject class 'TSNDecimal'
    T restkit.object_mapping:RKMappingOperation.m:542 Performing nested object mapping using mapping <RKRelationshipMapping: 0x95a0df0 amount => amount> for data: <TSNDecimal: 0x9652900> (entity: TSNDecimal; id: 0x9664220 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED165> ; data: {
                                                                                                                                                                                            number = 5;
                                                                                                                                                                                            })
    D restkit.object_mapping:RKMappingOperation.m:860 Starting mapping operation...
    T restkit.object_mapping:RKMappingOperation.m:861 Performing mapping operation: <RKMappingOperation 0x96b3d60> for 'TSNDecimal' object. Mapping values from object <TSNDecimal: 0x9652900> (entity: TSNDecimal; id: 0x9664220 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED165> ; data: {
                                                                                                                                                                                                number = 5;
                                                                                                                                                                                                }) ({
        mapping =     {
            collectionIndex = 3221208359;
        };
    }) to object <TSNDecimal: 0x96b2880> (entity: (null); id: (null) ; data: {
    }) with object mapping (null)
    T restkit.object_mapping:RKMappingOperation.m:439 Found transformable value at keyPath '(null)'. Transforming from class 'TSNDecimal' to 'NSDecimalNumber'
    E restkit.object_mapping:RKMappingOperation.m:441 Failed transformation of value at keyPath '(null)' to representation of type 'NSDecimalNumber': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value '<TSNDecimal: 0x9652900> (entity: TSNDecimal; id: 0x9664220 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED165> ; data: {
    number = 5;
    }) ({
        mapping =     {
            collectionIndex = 3221208359;
        };
    })' to NSDecimalNumber: none of the 2 value transformers consulted were successful." UserInfo=0x96bd900 {detailedErrors=(
    "Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 \"The given value is not already an instance of 'NSDecimalNumber'\" UserInfo=0x96bd630 {NSLocalizedDescription=The given value is not already an instance of 'NSDecimalNumber'}",
    "Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3000 \"Expected an `inputValue` of type `NSNull`, but got a `TSNDecimal`.\" UserInfo=0x96bd720 {NSLocalizedDescription=Expected an `inputValue` of type `NSNull`, but got a `TSNDecimal`.}"
    ), NSLocalizedDescription=Failed transformation of value '<TSNDecimal: 0x9652900> (entity: TSNDecimal; id: 0x9664220 <x-coredata:///TSNDecimal/tB2DF8887-7E6C-420F-998A-D250751E5CED165> ; data: {
    number = 5;
    }) ({
        mapping =     {
            collectionIndex = 3221208359;
        };
    })' to NSDecimalNumber: none of the 2 value transformers consulted were successful.}
    T restkit.object_mapping:RKMappingOperation.m:519 Did not find mappable attribute value keyPath '(null)'
    D restkit.object_mapping:RKMappingOperation.m:905 Mapping operation did not find any mappable values for the attribute and relationship mappings in the given object representation
    D restkit.object_mapping:RKMappingOperation.m:927 Failed mapping operation: No mappable values found for any of the attributes or relationship mappings
    W restkit.object_mapping:RKMappingOperation.m:553 WARNING: Failed mapping nested object: No mappable values found for any of the attributes or relationship mappings

The debugger show these mappings in -(BOOL)mapOneToManyRelationshipWithValue:mapping:

    (lldb) po relationshipMapping
<RKRelationshipMapping: 0x93d8330 amount => amount>

(lldb) po relationshipMapping.mapping
<RKEntityMapping:0x93b7d50 objectClass=TSNDecimal propertyMappings=
        (
        "<RKAttributeMapping: 0x93b8e60 (null) => number>"
        )>

debugging the object->JSON mapping

UPDATE 1

I noticed that when TSNDecimal is being serialized (or right before the mapping process) it is created again in RKMappingOperation.m, in -(id)destinationObjectForMappingRepresentation:parentRepresentation:withMapping:inRelationship: on line

return [self.dataSource mappingOperation:self targetObjectForRepre ...

TSNDecimalNumber recreated

with the wrong constructor new (that is why I see the coredata error: CoreData: error: Failed to call designated initializer on NSManagedObject class) later in the log. The self.dataSource calls wrong mappingOperation:targetObjectForRepresentation: as it is dataSource for non-managed objects (RKObjectMappingOperationDataSource). It should be RKManagedObjectMappingOperationDataSource.

I guessed it might be related issue to the RKObjectMapping v. RKEntityMapping problem. But when I use RKEntityMapping for TSNTagAmountRequest:

tagAmountRequestMapping = [RKEntityMapping mappingForEntityForName:[TSNTagAmountRequest class] inManagedObjectStore:managedObjectStore]; 

then I get the error: ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'RKRequestDescriptor objects must be initialized with a mapping whose target class is NSMutableDictionary, got 'TSNTagAmountRequest' (see [RKObjectMapping requestMapping])'**

UPDATE 2

I have changed the implementation so that it uses inverse mappings:

    RKObjectMapping* decimalMappingInverse        = [(RKEntityMapping*)decimalMapping inverseMapping];

    RKPropertyMapping* decimalPropertyMappingAmountInverse =
                  [RKRelationshipMapping relationshipMappingFromKeyPath:@"amount"
                                                              toKeyPath:@"amount"
                                                   withMapping:decimalMappingInverse];

    [tagAmountRequestMapping addPropertyMapping:decimalPropertyMappingAmountInverse];


requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:tagAmountRequestMapping
                                                          objectClass:[TSNTagAmountRequest class]
                                                          rootKeyPath:nil
                                                               method:RKRequestMethodPOST];
[_rkManager addRequestDescriptor:requestDescriptor];

With output with exception at the end of mapping operation Invalid (non-string) key in JSON dictionary:

 (
 {
     5 =         {
     };
 },
 {
     100 =         {
     };
 }
 )

And the log:

D restkit.object_mapping:RKMappingOperation.m:860 Starting mapping operation...
T restkit.object_mapping:RKMappingOperation.m:861 Performing mapping operation: <RKMappingOperation 0xf844d50> for '__NSDictionaryM' object. Mapping values from object <TSNTicketAmountApiRequest: 0xf80e9b0> (entity: TSNTicketAmountApiRequest; id: 0xf86bbe0 <x-coredata:///TSNTicketAmountApiRequest/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F66> ; data: {
                                                                                                                                                                                                                                                                   amount =     (
                                                                                                                                                                                                                                                                                 "0xf8c3b30 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F67>",
                                                                                                                                                                                                                                                                                 "0xf80c370 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F68>"
                                                                                                                                                                                                                                                                                 );

                                                                                                                                                                                                                                                                   }) ((null)) to object {
} with object mapping (null)
T restkit.object_mapping:RKMappingOperation.m:454 Mapping attribute value keyPath 'token' to 'token'
T restkit.object_mapping:RKMappingOperation.m:470 Mapped attribute value from keyPath 'token' to 'token'. Value: SXppH1ajA9OspKHkQ6Uwi7dD7AoYVP7J:api
T restkit.object_mapping:RKMappingOperation.m:454 Mapping attribute value keyPath 'bonification' to 'bonification'
T restkit.object_mapping:RKMappingOperation.m:470 Mapped attribute value from keyPath 'bonification' to 'bonification'. Value: 1
D restkit.network:RKObjectParameterization.m:129 Serialized NSDecimalNumber value at keyPath to __NSCFString (1)
T restkit.object_mapping:RKMappingOperation.m:454 Mapping attribute value keyPath 'isNetCurrency' to 'isNetCurrency'
T restkit.object_mapping:RKMappingOperation.m:470 Mapped attribute value from keyPath 'isNetCurrency' to 'isNetCurrency'. Value: 0
D restkit.network:RKObjectParameterization.m:129 Serialized __NSCFNumber value at keyPath to __NSCFBoolean (0)
D restkit.object_mapping:RKMappingOperation.m:641 Mapping one to many relationship value at keyPath 'amount' to 'amount'
T restkit.object_mapping:RKMappingOperation.m:542 Performing nested object mapping using mapping <RKRelationshipMapping: 0xf87bf40 amount => amount> for data: <TSNDecimalApiTO: 0xf8f0a60> (entity: TSNDecimalApiTO; id: 0xf8c3b30 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F67> ; data: {
                                                                                                                                                                                                                                                number = 5;
                                                                                                                                                                                                                                                })
D restkit.object_mapping:RKMappingOperation.m:860 Starting mapping operation...
T restkit.object_mapping:RKMappingOperation.m:861 Performing mapping operation: <RKMappingOperation 0x93779f0> for '__NSDictionaryM' object. Mapping values from object <TSNDecimalApiTO: 0xf8f0a60> (entity: TSNDecimalApiTO; id: 0xf8c3b30 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F67> ; data: {
                                                                                                                                                                                                                                                         number = 5;
                                                                                                                                                                                                                                                         }) ({
    mapping =     {
        collectionIndex = 3221208359;
    };
}) to object {
} with object mapping (null)
 T restkit.object_mapping:RKMappingOperation.m:439 Found transformable value at keyPath 'number'. Transforming from class 'NSDecimalNumber' to 'NSMutableDictionary'
 T restkit.object_mapping:RKMappingOperation.m:454 Mapping attribute value keyPath 'number' to '(null)'
 T restkit.object_mapping:RKMappingOperation.m:470 Mapped attribute value from keyPath 'number' to '(null)'. Value: {
    5 =     {
    };
}
 D restkit.object_mapping:RKMappingOperation.m:929 Finished mapping operation successfully...
 T restkit.object_mapping:RKMappingOperation.m:542 Performing nested object mapping using mapping <RKRelationshipMapping: 0xf87bf40 amount => amount> for data: <TSNDecimalApiTO: 0xf8f0ea0> (entity: TSNDecimalApiTO; id: 0xf80c370 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F68> ; data: {
                                                                                                                                                                                                                                                number = 100;
                                                                                                                                                                                                                                                })
 D restkit.object_mapping:RKMappingOperation.m:860 Starting mapping operation...
 T restkit.object_mapping:RKMappingOperation.m:861 Performing mapping operation: <RKMappingOperation 0x9311160> for '__NSDictionaryM' object. Mapping values from object <TSNDecimalApiTO: 0xf8f0ea0> (entity: TSNDecimalApiTO; id: 0xf80c370 <x-coredata:///TSNDecimalApiTO/t5BFB6379-F8EB-4367-A53B-E1B3C531A34F68> ; data: {
                                                                                                                                                                                                                                                         number = 100;
                                                                                                                                                                                                                                                         }) ({
    mapping =     {
        collectionIndex = 3221208359;
    };
}) to object {
} with object mapping (null)
 T restkit.object_mapping:RKMappingOperation.m:439 Found transformable value at keyPath 'number'. Transforming from class 'NSDecimalNumber' to 'NSMutableDictionary'
 T restkit.object_mapping:RKMappingOperation.m:454 Mapping attribute value keyPath 'number' to '(null)'
 T restkit.object_mapping:RKMappingOperation.m:470 Mapped attribute value from keyPath 'number' to '(null)'. Value: {

    };
}
 D restkit.object_mapping:RKMappingOperation.m:929 Finished mapping operation successfully...
 T restkit.object_mapping:RKMappingOperation.m:682 Mapped relationship object from keyPath 'amount' to 'amount'. Value: (
                                                                                                                                                                           {
                                                                                                                                                                               5 =         {
                                                                                                                                                                               };
                                                                                                                                                                           },
                                                                                                                                                                           {
                                                                                                                                                                               100 =         {
                                                                                                                                                                               };
                                                                                                                                                                           }
                                                                                                                                                                           )

In addition to the above exception the result does not match the required body {"amount":[5,100]}:

enter image description here

 D restkit.object_mapping:RKMappingOperation.m:929 Finished mapping operation successfully...
 exception Invalid (non-string) key in JSON dictionary

UPDATE 3

This issue boils down to the way how the array of decimal numbers from JSON are parsed to the NSSet of NSManagedObjects (working from very first moment) and vice versa, from NSSet to JSON array (quite frustrating to get it work):

{"amount":[10,20,50]}  

that is

TSNTagAmountRequest:{amount:[TSNDecimal, TSNDecimal, TSNDecimal, ...]}

Where

@interface TSNTagAmountRequest : NSManagedObject
@property(nonatomic) NSSet *amount;
@end

and

@interface TSNDecimal : NSManagedObject
@property(nonatomic) NSDecimalNumber* number; // is a helper property
@end

RKEntityMapping* tagAmountRequestMapping = [RKObjectMapping requestMapping];

[tagAmountRequestMapping  
      addPropertyMapping:decimalPropertyMappingAmountInverse];

where

    RKPropertyMapping* decimalPropertyMappingAmountInverse =
                              [RKRelationshipMapping 
                                relationshipMappingFromKeyPath:@"amount"
                                                     toKeyPath:@"amount"
                                                   withMapping:decimalMappingInverse];

where

 RKObjectMapping* decimalMappingInverse = [(RKEntityMapping*)decimalMapping inverseMapping];

where

 RKObjectMapping* decimalMapping = [RKEntityMapping mappingForEntityForName:@"TSNDecimal" inManagedObjectStore:managedObjectStore];
 [mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil          
                                                                   toKeyPath:@"number"]];


    requestDescriptor = [RKRequestDescriptor 
                      requestDescriptorWithMapping:tagAmountRequestMapping
                                       objectClass:[TSNTagAmountRequest class]
                                    rootKeyPath:TSNServiceClientRemoteRootKeyPathNotNested
                                         method:RKRequestMethodPOST];
[_rkManager addRequestDescriptor:requestDescriptor];

The method + (NSData *)dataFromObject:error: from RKNSJSONSerialization cannot consume the result object from mapping containing NSDictionary :

 (
 {
     5 =         {
     };
 },
 {
     100 =         {
     };
 }
 )

where I expect something like [5, 100].

The app crashes with Invalid (non-string) key in JSON dictionary.

I do not understand why [NSJSONSerialization dataWithJSONObject:object options:0 error:error]; is served this strange array of dictionaries instead of the array of NSDecimalNumbers.

UPDATE 4

I have changed the definition of the relationship mapping between TSNTagAmountRequest and TSNDecimal so that the value in TSNDecimal (item from amount NSSet) is propagated with its attribute "number".

RKPropertyMapping* decimalPropertyMappingAmountInverse =
                              [RKRelationshipMapping relationshipMappingFromKeyPath:@"amount.number"
                                                                          toKeyPath:@"amount"
                                                                        withMapping:decimalApiMappingInverse];

Restkit engine, exactly applyRelationshipMappings method from RKMappingOperation.m is able to extract amount values 5, 100 but the final JSON is assembled incorrectly anyway:

"amount":[{},{}]

with missing values. I'm almost there.

UPDATE 5

After setting up the inverseMapping's for all involved entities, feeding the request descriptor, still the output (driven by the mapping number->nil) is assembled incorrectly with dictionary of dictionaries, not a JSON array. The only way is to subclass RKNSJSONSerialization and fix the structure, that is, to translate the dictionary of dictionaries to simple nsarray which is compatible with ns json serializer.

Vladimír Slavík
  • 1,727
  • 1
  • 21
  • 31
  • `Why it is not possible to create the json body with RKRelationshipMapping` - because creating JSON is a request descriptor operation and you are only using response descriptors. Other than that there is no restriction really. I suggest you show real code and the real JSON that is coming in or that you want out as your current question doesn't make much sense. – Wain Jun 16 '14 at 20:40
  • Thank you Wain again. I have updated the question. I was trying to solve it but I could not find the way on my own. – Vladimír Slavík Jun 17 '14 at 11:00
  • Still no success. There must be something obvious when serializing NSSet of NSManagedObjects to JSON array. – Vladimír Slavík Jun 17 '14 at 21:27
  • You seem to be making progress, but to have confusion between request and response descriptor purpose and with nil key path mappings. Generally, create a response mapping and descriptor, then take the inverse mapping and create the request descriptor. The response mapping should use the nil key path and the inverse should generally not be modified in any way. – Wain Jun 18 '14 at 19:31
  • I think the instructions from Restkit page ( https://github.com/RestKit/RestKit/wiki/Object-mapping#mapping-values-without-key-paths ) do not work for the inverseMapping. I did not see a code which works. But I need to confirm it. I assume the inverseMapping for [RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"number"]] is [RKAttributeMapping attributeMappingFromKeyPath:@"number" toKeyPath:nil]]. – Vladimír Slavík Jun 18 '14 at 19:45
  • Yes, it should work and it should be (but just calling `inverseMapping` should do that for you). – Wain Jun 18 '14 at 19:48
  • Ok I will push it. The crucial difference from the example on the Restkit page is the fact that I use relationshipMappingFromKeyPath to setup the relationship between the request object and the "amount" NSSet of TSNDecimal's. – Vladimír Slavík Jun 18 '14 at 19:57
  • When using the inverted mapping (number->nil) and the amount->amount relationship the restkit engine passes values to nsjson serializer as dictionary containing two dictionaries (one for number 5, one for 100), and more surprisingly, the values which should go to brackets are the keys: https://www.dropbox.com/s/39wytw4gq6i03f5/Screenshot%202014-06-18%2022.11.38.png – Vladimír Slavík Jun 18 '14 at 20:18
  • Have you tried turning on forced collection mapping? I haven't tried to do exactly what you're trying before. – Wain Jun 18 '14 at 20:29
  • The datasource used in destinationObjectForMappingRepresentation (RKMappingOperation.m) is RKObjectMappingOperationDataSource. I would expect RKManagedObjectMappingOperationDataSource as the representation variable is of type TSNDecimal(NSManagedObject). Everything what is necessary for the mapping is at my hand in the method. The only issue is the datasource. I have created an issue in github, but was gracefully recommended to go away:) It looks like the NSManagedObject -> JSON mapping does not work for relationships. – Vladimír Slavík Jun 18 '14 at 20:54
  • Yes I have forced it, but the error was logged, something similar to "you do not use NSDictionary but NSSet". (the amount attribute is NSSet). – Vladimír Slavík Jun 18 '14 at 20:56
  • I think this paragraph from the wiki is related to the issue: "5. To create the object request operation, the method must first determine the appropriate type of operation to construct. This is determined by examining the type of the object and the set of RKResponseDescriptor objects registered with the manager. If the object is an instance of NSManagedObject or one of its subclasses or the set of request descriptors contains an RKEntityMapping, then an instance of RKManagedObjectRequestOperation is created, else an RKObjectRequestOperation is constructed." – Vladimír Slavík Jun 18 '14 at 21:03
  • Also I have created this request descriptor requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:decimalMappingInverse objectClass:[TSNDecimal class] rootKeyPath:@"amount" method:RKRequestMethodAny]; and it does not help either. – Vladimír Slavík Jun 18 '14 at 21:28
  • The managed object part is only used for response processing, not request processing. Your question indicates you only have an issue with requests, but that you are confused by what is used when... – Wain Jun 18 '14 at 21:33
  • This isn't a bug report (yet), so you need to ask here or on the google group https://groups.google.com/forum/#!forum/restkit – Wain Jun 18 '14 at 21:36
  • According to what I see during debug session there is correctly extracted the NSSet of TSNDecimal's. The datasource member, as i have written above, is of type RKObjectMappingOperationDataSource which instantiates whatever it wants to map, that is, also the items from the "amount" NSSet, which happen to be NSManagedObjects. In other words, RKObjectMappingOperationDataSource is passed correct mapping but uses wrong constructors with NSManagedObject class: return [mapping.objectClass new]; – Vladimír Slavík Jun 18 '14 at 21:44
  • Do you have a non managed object mapping somewhere that you haven't shown in the question? – Wain Jun 19 '14 at 07:30
  • All objects involved are inherited from NSManagedObject, except attributes of these objects like strings, numbers. I think the mapping strategy is (at least in my case) somehow incorrectly deduced from the participants (as stated in the paragraph "5. To create the object request operation ..." on the wiki page). All object mappings are of type RKObjectMapping (inverted RKEntityMappings) Maybe there is the culprit hidden. – Vladimír Slavík Jun 19 '14 at 08:06
  • More precisely in - (id)destinationObjectForMappingRepresentation:(id)representation parentRepresentation:(id)parentRepresentation withMapping:(RKMapping *)mapping in RKMappingOperation. The statement NSDictionary *dictionaryRepresentation = [representation isKindOfClass:[NSDictionary class]] ? representation : @{ [NSNull null] : representation }; is the first moment when the process diverges from the right path:) Another way could be to avoid NSManagedObjects at all but then I am forced to create NSObject entities with duplicate functionality. – Vladimír Slavík Jun 19 '14 at 08:07
  • `RKObjectMapping` should be used only for request mappings in your case, and `RKEntityMappings` for all response mappings. – Wain Jun 19 '14 at 11:05
  • Yes calling inverseMapping on RKEntityMappings returns RKObjectMapping instance. – Vladimír Slavík Jun 19 '14 at 12:34

0 Answers0