mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
412b6b3839
* Package objc client using cocoapods. * Support cli options.
40 lines
1.3 KiB
Objective-C
40 lines
1.3 KiB
Objective-C
#import "SWGJSONResponseSerializer.h"
|
|
|
|
static BOOL JSONParseError(NSError *error) {
|
|
if ([error.domain isEqualToString:NSCocoaErrorDomain] && error.code == 3840) {
|
|
return YES;
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
@implementation SWGJSONResponseSerializer
|
|
|
|
///
|
|
/// When customize a response serializer,
|
|
/// the serializer must conform the protocol `AFURLResponseSerialization`
|
|
/// and implements the protocol method `responseObjectForResponse:error:`
|
|
///
|
|
/// @param response The response to be processed.
|
|
/// @param data The response data to be decoded.
|
|
/// @param error The error that occurred while attempting to decode the respnse data.
|
|
///
|
|
/// @return The object decoded from the specified response data.
|
|
///
|
|
- (id) responseObjectForResponse:(NSURLResponse *)response
|
|
data:(NSData *)data
|
|
error:(NSError *__autoreleasing *)error {
|
|
NSDictionary *responseJson = [super responseObjectForResponse:response data:data error:error];
|
|
|
|
// if response data is not a valid json, return string of data.
|
|
if (JSONParseError(*error)) {
|
|
*error = nil;
|
|
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
return responseString;
|
|
}
|
|
|
|
return responseJson;
|
|
}
|
|
|
|
@end
|