aryaxt / OCMapper

Objective-C library to easily map NSDictionary to model objects, works perfectly with Alamofire. ObjectMapper works similar to GSON
MIT License
347 stars 45 forks source link

Property name mapping doesn't support underscore at the middle of the property name? #47

Closed seaguest closed 8 years ago

seaguest commented 8 years ago

Hello,

I just found a problem of property name mapping when we have underscore at the middle of the property.

This is linked to https://github.com/aryaxt/OCMapper/issues/46

My Model is:

@interface User : NSObject
@property (nonatomic) int user_id;
@property (nonatomic) NSString* registration;
@end

The dictionary is:

{
    registration = "my test registration";
    "user_id" = 10;
}

However OCMapper mapped user_id to userid(without underscore), I guess this is not supposed to be, you may want to map userid to _userid but forgetting the case when we have underscore at the middle.

Ok, I see the code in

    @implementation ObjectInstanceProvider

    // Support underscore case (EX: map first_name to firstName)
    caseInsensitivePropertyName = [caseInsensitivePropertyName stringByReplacingOccurrencesOfString:@"_" withString:@""];

I just saw that automatic underscore mapping from the latest changelog, but what if we want to keep the same name as in he dictionary?

seaguest commented 8 years ago

as a workaround, I just removed that line of code, but it would be better if it can allow user to choose wither default same name mapping or differen name mapping.

aryaxt commented 8 years ago

Hi, yes sorry this is not supported, objective c property naming convention is camel case

lorenzoPrimi commented 6 years ago

That was really annoying, spent two hours debugging it to discover that the component remove the underscores in the var names. As I want to use the Pod, can that replace be optional instead of compulsory?