Shun87 / wsdl2objc

Automatically exported from code.google.com/p/wsdl2objc
MIT License
0 stars 0 forks source link

Problem with conversion of large integer numbers #112

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

when the WSDL specifies a numeric field that is actually field with a large 
integer number, the default conversion to a double carries some risk that the 
number becomes corrupt. In my case this occurred dealing with authentication 
tokens, that for some reason were carried as numbers like 4602693606284514801, 
and not as strings.

I suggest to slighlty generalize the deserializeNode: method of the NSNumber 
USAdditions in USAdditions_M.template in the following way:

+ (NSNumber *)deserializeNode:(xmlNodePtr)cur
{
    NSString *stringValue = [NSString deserializeNode:cur];
    NSRange rangeOfDot= [stringValue rangeOfString:@"."];
    if (rangeOfDot.location != NSNotFound)
        return [NSNumber numberWithDouble:[stringValue doubleValue]];
    else
        return [NSNumber numberWithLongLong:[stringValue longLongValue]];
}

This ensures that if the number is floating point the widest floating point 
format is used, and when it is an integer number the widest integer format is 
used. This simple solution solved the problem in my case.

Best regards,

   Gianluca Bertani
   Flying Dolphin Studio

Original issue reported on code.google.com by flyingdo...@gmail.com on 25 Aug 2010 at 1:46