Skip to content

Commit 53b45c1

Browse files
committed
support coding
1 parent 67b7e57 commit 53b45c1

File tree

22 files changed

+955
-272
lines changed

22 files changed

+955
-272
lines changed

CHANGELOG.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,5 @@
55
## new
66
- Add documentation
77

8-
## [1.0.0](https://github.com/kakaopensource/KakaJSON/releases/tag/1.0.0) (2019-08-20)
9-
- First public release
10-
- Add interfaces for `Data\NSData`
11-
- Add `JSONObject``JSONObjectArray`
12-
- Add more test cases
13-
- Add more interfaces for global config
14-
- Add global config
15-
- Add test case of CGFloat
16-
- Support conversion from Date to Number
17-
- Support conversion from Double to Date
18-
- Support conversion between set and array
19-
- Support Xcode10
20-
- Enhance enum type
21-
- Update chinese manual
22-
- Fix a bug in release mode
23-
- Merged pull requests
24-
- [Support swift package manage #9](https://github.com/kakaopensource/KakaJSON/pull/9)
25-
- [Use range to judge index #8](https://github.com/kakaopensource/KakaJSON/pull/8)
8+
## [1.0.0](https://github.com/kakaopensource/KakaJSON/releases/tag/1.0.0) (2019-08-22)
9+
- First public release

KakaJSON.xcodeproj/project.pbxproj

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
2D0575832308F41400810526 /* CompareWithCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D0575822308F41400810526 /* CompareWithCodable.swift */; };
1111
2D0AC2B523099A4B00992F29 /* Data+KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D0AC2B423099A4B00992F29 /* Data+KJ.swift */; };
1212
2D0DD8682306785E00937EF2 /* JTM_02_DataType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D0DD8672306785E00937EF2 /* JTM_02_DataType.swift */; };
13+
2D49E3DB230E4F4100F57D8F /* Value.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D49E3DA230E4F4100F57D8F /* Value.swift */; };
14+
2D49E3DE230E4FB300F57D8F /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D49E3DD230E4FB300F57D8F /* Model.swift */; };
15+
2D49E3E0230E52A200F57D8F /* Coding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D49E3DF230E52A200F57D8F /* Coding.swift */; };
16+
2D49E3E2230E545D00F57D8F /* Coding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D49E3E1230E545D00F57D8F /* Coding.swift */; };
1317
2D5253AE2305461300F854D9 /* NSObject+KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D5253AD2305461300F854D9 /* NSObject+KJ.swift */; };
1418
2D5875C82301B6E4001A809B /* MTJ_02_NestedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D5875C72301B6E4001A809B /* MTJ_02_NestedModel.swift */; };
1519
2D5875CA2301C2C4001A809B /* MTJ_03_ModelArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D5875C92301C2C4001A809B /* MTJ_03_ModelArray.swift */; };
@@ -31,7 +35,7 @@
3135
2D92DDDE2301279E00A96858 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB02301279E00A96858 /* Logger.swift */; };
3236
2D92DDDF2301279E00A96858 /* Convertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB12301279E00A96858 /* Convertible.swift */; };
3337
2D92DDE02301279E00A96858 /* KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB22301279E00A96858 /* KJ.swift */; };
34-
2D92DDE42301279E00A96858 /* KakaJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB62301279E00A96858 /* KakaJSON.swift */; };
38+
2D92DDE42301279E00A96858 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB62301279E00A96858 /* JSON.swift */; };
3539
2D92DDE52301279E00A96858 /* Pointer+KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB82301279E00A96858 /* Pointer+KJ.swift */; };
3640
2D92DDE62301279E00A96858 /* Dictionary+KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDB92301279E00A96858 /* Dictionary+KJ.swift */; };
3741
2D92DDE72301279E00A96858 /* String+KJ.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D92DDBA2301279E00A96858 /* String+KJ.swift */; };
@@ -85,6 +89,10 @@
8589
2D0AC2B423099A4B00992F29 /* Data+KJ.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+KJ.swift"; sourceTree = "<group>"; };
8690
2D0DD8672306785E00937EF2 /* JTM_02_DataType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JTM_02_DataType.swift; sourceTree = "<group>"; };
8791
2D0EAA0E2303C0EB000691AC /* DevGuidline.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DevGuidline.h; sourceTree = "<group>"; };
92+
2D49E3DA230E4F4100F57D8F /* Value.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Value.swift; sourceTree = "<group>"; };
93+
2D49E3DD230E4FB300F57D8F /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
94+
2D49E3DF230E52A200F57D8F /* Coding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coding.swift; sourceTree = "<group>"; };
95+
2D49E3E1230E545D00F57D8F /* Coding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Coding.swift; sourceTree = "<group>"; };
8896
2D5253AD2305461300F854D9 /* NSObject+KJ.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSObject+KJ.swift"; sourceTree = "<group>"; };
8997
2D5875C72301B6E4001A809B /* MTJ_02_NestedModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTJ_02_NestedModel.swift; sourceTree = "<group>"; };
9098
2D5875C92301C2C4001A809B /* MTJ_03_ModelArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MTJ_03_ModelArray.swift; sourceTree = "<group>"; };
@@ -111,7 +119,7 @@
111119
2D92DDB02301279E00A96858 /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
112120
2D92DDB12301279E00A96858 /* Convertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Convertible.swift; sourceTree = "<group>"; };
113121
2D92DDB22301279E00A96858 /* KJ.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KJ.swift; sourceTree = "<group>"; };
114-
2D92DDB62301279E00A96858 /* KakaJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KakaJSON.swift; sourceTree = "<group>"; };
122+
2D92DDB62301279E00A96858 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
115123
2D92DDB82301279E00A96858 /* Pointer+KJ.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Pointer+KJ.swift"; sourceTree = "<group>"; };
116124
2D92DDB92301279E00A96858 /* Dictionary+KJ.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+KJ.swift"; sourceTree = "<group>"; };
117125
2D92DDBA2301279E00A96858 /* String+KJ.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+KJ.swift"; sourceTree = "<group>"; };
@@ -169,6 +177,26 @@
169177
/* End PBXFrameworksBuildPhase section */
170178

171179
/* Begin PBXGroup section */
180+
2D49E3DC230E4F4900F57D8F /* Global */ = {
181+
isa = PBXGroup;
182+
children = (
183+
2D92DDB62301279E00A96858 /* JSON.swift */,
184+
2D49E3DA230E4F4100F57D8F /* Value.swift */,
185+
2D49E3DD230E4FB300F57D8F /* Model.swift */,
186+
2D49E3E1230E545D00F57D8F /* Coding.swift */,
187+
);
188+
path = Global;
189+
sourceTree = "<group>";
190+
};
191+
2D49E3E3230E556700F57D8F /* Other */ = {
192+
isa = PBXGroup;
193+
children = (
194+
2D0575822308F41400810526 /* CompareWithCodable.swift */,
195+
2D49E3DF230E52A200F57D8F /* Coding.swift */,
196+
);
197+
path = Other;
198+
sourceTree = "<group>";
199+
};
172200
2D92DD0F2301262500A96858 = {
173201
isa = PBXGroup;
174202
children = (
@@ -190,10 +218,10 @@
190218
2D92DD1B2301262500A96858 /* KakaJSON */ = {
191219
isa = PBXGroup;
192220
children = (
221+
2D49E3DC230E4F4900F57D8F /* Global */,
193222
2D92DDB72301279E00A96858 /* Extension */,
194-
2D92DDAF2301279E00A96858 /* JSON */,
223+
2D92DDAF2301279E00A96858 /* Convert */,
195224
2D92DDBD2301279E00A96858 /* Metadata */,
196-
2D92DDB62301279E00A96858 /* KakaJSON.swift */,
197225
2D92DD1C2301262500A96858 /* KakaJSON.h */,
198226
2D0EAA0E2303C0EB000691AC /* DevGuidline.h */,
199227
2D92DD1D2301262500A96858 /* Info.plist */,
@@ -206,8 +234,8 @@
206234
children = (
207235
2D92DDA2230126BD00A96858 /* JSON_To_Model */,
208236
2D92DDA0230126BD00A96858 /* Model_To_JSON */,
237+
2D49E3E3230E556700F57D8F /* Other */,
209238
2D92DD9F230126BD00A96858 /* Common.swift */,
210-
2D0575822308F41400810526 /* CompareWithCodable.swift */,
211239
2D92DD292301262500A96858 /* Info.plist */,
212240
2D92DD9C230126A100A96858 /* KakaJSONTests-Bridging-Header.h */,
213241
);
@@ -240,7 +268,7 @@
240268
path = JSON_To_Model;
241269
sourceTree = "<group>";
242270
};
243-
2D92DDAF2301279E00A96858 /* JSON */ = {
271+
2D92DDAF2301279E00A96858 /* Convert */ = {
244272
isa = PBXGroup;
245273
children = (
246274
2D92DDB02301279E00A96858 /* Logger.swift */,
@@ -250,7 +278,7 @@
250278
2D92DDB22301279E00A96858 /* KJ.swift */,
251279
2D645BA02302995100075A9E /* TypeProxy.swift */,
252280
);
253-
path = JSON;
281+
path = Convert;
254282
sourceTree = "<group>";
255283
};
256284
2D92DDB72301279E00A96858 /* Extension */ = {
@@ -444,6 +472,7 @@
444472
2D92DDF32301279E00A96858 /* BaseLayout.swift in Sources */,
445473
2D92DDEE2301279E00A96858 /* FunctionLayout.swift in Sources */,
446474
2D92DDED2301279E00A96858 /* ClassLayout.swift in Sources */,
475+
2D49E3DE230E4FB300F57D8F /* Model.swift in Sources */,
447476
2D92DE052301279E00A96858 /* EnumDescriptor.swift in Sources */,
448477
2D92DE022301279E00A96858 /* ClassDescriptor.swift in Sources */,
449478
2D92DDF22301279E00A96858 /* EnumLayout.swift in Sources */,
@@ -462,10 +491,12 @@
462491
2D92DDFC2301279E00A96858 /* MetaType.swift in Sources */,
463492
2D92DDE82301279E00A96858 /* Optional+KJ.swift in Sources */,
464493
2D92DDF42301279E00A96858 /* StructLayout.swift in Sources */,
494+
2D49E3DB230E4F4100F57D8F /* Value.swift in Sources */,
465495
2D0AC2B523099A4B00992F29 /* Data+KJ.swift in Sources */,
466496
2D5253AE2305461300F854D9 /* NSObject+KJ.swift in Sources */,
467497
2D92DDE62301279E00A96858 /* Dictionary+KJ.swift in Sources */,
468498
2D92DDEA2301279E00A96858 /* Metadata.swift in Sources */,
499+
2D49E3E2230E545D00F57D8F /* Coding.swift in Sources */,
469500
2D645D3F23058B2500046636 /* ConvertibleConfig.swift in Sources */,
470501
2D645BA12302995100075A9E /* TypeProxy.swift in Sources */,
471502
2D92DDEF2301279E00A96858 /* ProtocolLayout.swift in Sources */,
@@ -476,7 +507,7 @@
476507
2D92DE002301279E00A96858 /* EnumType.swift in Sources */,
477508
2D92DDFF2301279E00A96858 /* BaseType.swift in Sources */,
478509
2D92DDE72301279E00A96858 /* String+KJ.swift in Sources */,
479-
2D92DDE42301279E00A96858 /* KakaJSON.swift in Sources */,
510+
2D92DDE42301279E00A96858 /* JSON.swift in Sources */,
480511
2D92DDF92301279E00A96858 /* ProtocolType.swift in Sources */,
481512
2D92DDE02301279E00A96858 /* KJ.swift in Sources */,
482513
2D92DDEC2301279E00A96858 /* FieldList.swift in Sources */,
@@ -496,6 +527,7 @@
496527
2D5875CA2301C2C4001A809B /* MTJ_03_ModelArray.swift in Sources */,
497528
2D92DDAB230126BD00A96858 /* JTM_05_KeyMapping.swift in Sources */,
498529
2D0DD8682306785E00937EF2 /* JTM_02_DataType.swift in Sources */,
530+
2D49E3E0230E52A200F57D8F /* Coding.swift in Sources */,
499531
2D92DDAC230126BD00A96858 /* JTM_01_Basic.swift in Sources */,
500532
2D92DDAD230126BD00A96858 /* JTM_03_NestedModel.swift in Sources */,
501533
2D5875C82301B6E4001A809B /* MTJ_02_NestedModel.swift in Sources */,

KakaJSON.xcodeproj/xcshareddata/xcschemes/KakaJSON.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</BuildActionEntries>
2424
</BuildAction>
2525
<TestAction
26-
buildConfiguration = "Release"
26+
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

KakaJSON/Extension/JSONSerialization+KJ.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ extension JSONSerialization {
2121

2222
static func kj_string(_ json: Any?,
2323
prettyPrinted: Bool = false) -> String? {
24-
guard let value = json,
25-
let data = try? data(withJSONObject: value,
26-
options: prettyPrinted ? [.prettyPrinted] : [])
24+
guard let value = json else { return nil }
25+
guard value is [Any] || value is [String: Any] else {
26+
return "\(value)"
27+
}
28+
guard let data = try? data(withJSONObject: value,
29+
options: prettyPrinted ? [.prettyPrinted] : [])
2730
else { return nil }
2831
return String(data: data, encoding: .utf8)
2932
}

0 commit comments

Comments
 (0)