-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJSONJoy.h
112 lines (93 loc) · 3.48 KB
/
JSONJoy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// JSONJoy.h
//
// Created by Dalton Cherry on 10/23/13.
//
////////////////////////////////////////////////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
@interface JSONJoy : NSObject
///-------------------------------
/// @name Error codes For JSONJoy
///-------------------------------
typedef enum {
JSONJoyErrorCodeIncorrectType = 1 //this is returned when the expected type does not match in the JSON Object
} JSONJoyErrorCode;
///-------------------------------
/// @name Initalizing a JSONJoy Object
///-------------------------------
/**
Initializes and returns a JSONJoy object with the class that the json will be converted to.
@param classObj is the class to map the JSON Object to.
@return a new JSONJoy object.
*/
-(instancetype)initWithClass:(Class)classObj;
///-------------------------------
/// @name Mapping/Parsing JSON
///-------------------------------
/**
Adds an array mapping to JSON objects with an a JSON array.
*/
-(void)addArrayClassMap:(NSString*)propertyName class:(Class)classID;
/**
Runs the conversion process and returns a new object of the class provided.
@param jsonObj is a json Object or json String to parse.
@param error returns a valid object if an error occures.
@return a new parse object of the the class provided.
*/
-(id)process:(id)JSONObject error:(NSError**)error;
/**
retrieves all the property key names.
@return an array of all the property keys on the object.
*/
-(NSArray*)propertyKeys;
///-------------------------------
/// @name Factory Methods
///-------------------------------
/**
Factory method to create a JSONJoy object with a class.
*/
+(instancetype)JSONJoyWithClass:(Class)classType;
///-------------------------------
/// @name Class Methods
///-------------------------------
/**
@return returns a string formatted to snake case/JSON name.
@param propName is the property name you want converted. (e.g. avatarThumbUrl to avatar_thumb_url).
*/
+(NSString*)convertToJsonName:(NSString*)propName;
/**
sets if JSONJoy should try to do a loose property matching that ignores case.
@param set if loose should be enabled. Default is NO.
*/
+(void)setLoose:(BOOL)loose;
/**
sets if JSONJoy should auto box/convert BOOL types
to NSNumber or NSString if the property is set to that.
@param set if auto boxing of BOOLs should be enabled. Default is YES.
*/
+(void)setAutoConvertBOOLs:(BOOL)box;
@end
///-------------------------------
/// @name Category Methods
///-------------------------------
@interface NSObject (JSONJoy)
/**
Category on NSObject that creates a JSONJoy object. The other category methods call this one as well, so you can provide customizations as needed.
@return a new JSONJoy object.
*/
+(JSONJoy*)jsonMapper;
/**
Category on NSObject that creates a JSONJoy object and runs the process method to create a new object from the JSONObject provided.
@param jsonObj is a json Object or json String to parse.
@return a new parse object of the class running the parsing.
*/
+(id)objectWithJoy:(id)jsonObj;
/**
Category on NSObject that creates a JSONJoy object and runs the process method to create a new object from the JSONObject provided.
@param jsonObj is a json Object or json String to parse.
@param error returns a valid object if an error occures.
@return a new parse object of the class running the parsing.
*/
+(id)objectWithJoy:(id)jsonObj error:(NSError**)error;
@end