Skip to content

Commit

Permalink
fixed issue 39
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderMJLee committed Jan 7, 2020
1 parent 331c815 commit 88d8587
Show file tree
Hide file tree
Showing 16 changed files with 532 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

---

## [1.1.2](https://github.com/kakaopensource/KakaJSON/releases/tag/1.1.2) (2019-12-23)
- Supporting convert from [String: [[String: Any]]] to [String: [Model]]
- Supporting 'enum array', 'enum dict'
- Closed issues
- [嵌套解析出错](https://github.com/kakaopensource/KakaJSON/issues/39)

## [1.1.1](https://github.com/kakaopensource/KakaJSON/releases/tag/1.1.1) (2019-11-04)
- Adjust Lock
- Closed issues
Expand Down
2 changes: 1 addition & 1 deletion KakaJSON.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "KakaJSON"
s.version = "1.1.1"
s.version = "1.1.2"
s.summary = "Fast conversion between JSON and model in Swift"
s.homepage = "https://github.com/kakaopensource/KakaJSON"
s.license = { :type => "MIT" }
Expand Down
38 changes: 37 additions & 1 deletion KakaJSON.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
2D6B733823C4DDE40021DF3A /* Bugs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D4BC67323C4A29B00A2C4D6 /* Bugs.swift */; };
2D79463E23B0D10B00B9B538 /* OCModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D79463D23B0D10B00B9B538 /* OCModel.m */; };
627B5E462320EC490046E23D /* Metadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B5E0F2320EC480046E23D /* Metadata.swift */; };
627B5E472320EC490046E23D /* Property.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B5E102320EC480046E23D /* Property.swift */; };
627B5E482320EC490046E23D /* FieldList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B5E132320EC480046E23D /* FieldList.swift */; };
Expand Down Expand Up @@ -106,6 +108,10 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
2D4BC67323C4A29B00A2C4D6 /* Bugs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bugs.swift; sourceTree = "<group>"; };
2D79463B23B0D10A00B9B538 /* KakaJSONTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "KakaJSONTests-Bridging-Header.h"; sourceTree = "<group>"; };
2D79463C23B0D10B00B9B538 /* OCModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OCModel.h; sourceTree = "<group>"; };
2D79463D23B0D10B00B9B538 /* OCModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OCModel.m; sourceTree = "<group>"; };
627B5E0F2320EC480046E23D /* Metadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Metadata.swift; sourceTree = "<group>"; };
627B5E102320EC480046E23D /* Property.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Property.swift; sourceTree = "<group>"; };
627B5E112320EC480046E23D /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -172,7 +178,7 @@
627B5E972320F08F0046E23D /* KakaJSON.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = KakaJSON.podspec; sourceTree = "<group>"; };
627B5E992320F2710046E23D /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
627B5E9A2320F2D40046E23D /* DevGuideline.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = DevGuideline.md; sourceTree = "<group>"; };
"KakaJSON::KakaJSON::Product" /* KakaJSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = KakaJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"KakaJSON::KakaJSON::Product" /* KakaJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = KakaJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; };
"KakaJSON::KakaJSONTests::Product" /* KakaJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = KakaJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_13 /* XCTestManifests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCTestManifests.swift; sourceTree = "<group>"; };
OBJ_6 /* Package.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
Expand All @@ -197,6 +203,16 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
2D79463723B0D0C600B9B538 /* OC */ = {
isa = PBXGroup;
children = (
2D79463C23B0D10B00B9B538 /* OCModel.h */,
2D79463D23B0D10B00B9B538 /* OCModel.m */,
2D79463B23B0D10A00B9B538 /* KakaJSONTests-Bridging-Header.h */,
);
path = OC;
sourceTree = "<group>";
};
627B5E0E2320EC480046E23D /* Metadata */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -315,6 +331,7 @@
children = (
627B5E7D2320EC760046E23D /* Coding.swift */,
627B5E7E2320EC760046E23D /* Global.swift */,
2D4BC67323C4A29B00A2C4D6 /* Bugs.swift */,
);
path = Other;
sourceTree = "<group>";
Expand Down Expand Up @@ -362,6 +379,7 @@
OBJ_11 /* KakaJSONTests */ = {
isa = PBXGroup;
children = (
2D79463723B0D0C600B9B538 /* OC */,
627B5E7F2320EC760046E23D /* JSON_To_Model */,
627B5E762320EC760046E23D /* Model_To_JSON */,
627B5E7C2320EC760046E23D /* Other */,
Expand Down Expand Up @@ -469,6 +487,14 @@
attributes = {
LastSwiftMigration = 9999;
LastUpgradeCheck = 9999;
TargetAttributes = {
"KakaJSON::KakaJSON" = {
LastSwiftMigration = 1030;
};
"KakaJSON::KakaJSONTests" = {
LastSwiftMigration = 1030;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "KakaJSON" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -559,13 +585,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 0;
files = (
2D6B733823C4DDE40021DF3A /* Bugs.swift in Sources */,
627B5E902320EC760046E23D /* JTM_06_CustomValue.swift in Sources */,
627B5E922320EC760046E23D /* JTM_07_DynamicModel.swift in Sources */,
627B5E8D2320EC760046E23D /* Global.swift in Sources */,
627B5E8F2320EC760046E23D /* JTM_02_DataType.swift in Sources */,
627B5E8B2320EC760046E23D /* MTJ_03_ModelArray.swift in Sources */,
627B5E932320EC760046E23D /* JTM_04_ModelArray.swift in Sources */,
627B5E8A2320EC760046E23D /* MTJ_01_Basic.swift in Sources */,
2D79463E23B0D10B00B9B538 /* OCModel.m in Sources */,
627B5E912320EC760046E23D /* JTM_05_KeyMapping.swift in Sources */,
627B5E8C2320EC760046E23D /* Coding.swift in Sources */,
627B5E882320EC760046E23D /* MTJ_05_CustomValue.swift in Sources */,
Expand Down Expand Up @@ -596,6 +624,8 @@
OBJ_19 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -614,6 +644,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGET_NAME = KakaJSON;
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -624,6 +655,8 @@
OBJ_20 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
DEFINES_MODULE = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -725,6 +758,8 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/KakaJSONTests/OC/KakaJSONTests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGET_NAME = KakaJSONTests;
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -751,6 +786,7 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/KakaJSONTests/OC/KakaJSONTests-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGET_NAME = KakaJSONTests;
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand Down
139 changes: 136 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

### CocoaPods
```ruby
pod 'KakaJSON', '~> 1.1.1'
pod 'KakaJSON', '~> 1.1.2'
```

### Carthage
```ruby
github "kakaopensource/KakaJSON" ~> 1.1.1
github "kakaopensource/KakaJSON" ~> 1.1.2
```

### Swift Package Manager
Expand Down Expand Up @@ -54,6 +54,7 @@ Or you can login Xcode with your GitHub account. just search **KakaJSON**.
- [Recursive](#recursive)
- [Generic](#generic)
- [Model Array](#model-array)
- [Model Array In Dictionary](#model-array-in-dictionary)
- [Convert](#convert)
- [Listen](#listen)
- [JSON To Model_02_Data Type](#json-to-model_02_data-type)
Expand All @@ -71,6 +72,9 @@ Or you can login Xcode with your GitHub account. just search **KakaJSON**.
- [Data](#data)
- [Date](#date)
- [Enum](#enum)
- [Enum In Array](#enum-in-array)
- [Enum In Dictionary](#enum-in-dictionary)
- [Enum Array In Dictionary](#enum-array-in-dictionary)
- [Array](#array)
- [Set](#set)
- [Dictionary](#dictionary)
Expand Down Expand Up @@ -635,6 +639,58 @@ let cars7 = jsonString.kj.modelArray(type: type) as? [Car]
let cars8 = modelArray(from: jsonString, type: type) as? [Car]
```

### Model Array In Dictionary
```swift
struct Book: Convertible {
var name: String = ""
var price: Double = 0.0
}

struct Person: Convertible {
var name: String = ""
var books: [String: [Book?]?]?
}

let name = "Jack"
let mobileBooks = [
(name: "iOS", price: 10.5),
(name: "Android", price: 8.5)
]
let serverBooks = [
(name: "Java", price: 20.5),
(name: "Go", price: 18.5)
]

let json: [String: Any] = [
"name": name,
"books": [
"mobile": [
["name": mobileBooks[0].name, "price": mobileBooks[0].price],
["name": mobileBooks[1].name, "price": mobileBooks[1].price]
],
"server": [
["name": serverBooks[0].name, "price": serverBooks[0].price],
["name": serverBooks[1].name, "price": serverBooks[1].price]
]
]
]

let person = json.kj.model(Person.self)
XCTAssert(person.name == name)
let books0 = person.books?["mobile"]
XCTAssert(books0??.count == mobileBooks.count)
for i in 0..<mobileBooks.count {
XCTAssert(books0??[i]?.name == mobileBooks[i].name);
XCTAssert(books0??[i]?.price == mobileBooks[i].price);
}
let books1 = person.books?["server"]
XCTAssert(books1??.count == serverBooks.count)
for i in 0..<serverBooks.count {
XCTAssert(books1??[i]?.name == serverBooks[i].name);
XCTAssert(books1??[i]?.price == serverBooks[i].price);
}
```

### Convert
```swift
struct Cat: Convertible {
Expand All @@ -651,7 +707,7 @@ var cat = Cat()
// fill a cat instance with json
// .kj_m is a mutable version of .kj
cat.kj_m.convert(json)
XCTAssert(cat.name == "Miaomiao"
XCTAssert(cat.name == "Miaomiao")
XCTAssert(cat.weight == 6.66)

```
Expand Down Expand Up @@ -1276,6 +1332,83 @@ XCTAssert(student2?.grade3 == .great)
XCTAssert(student2?.grade4 == .perfect)
```

### Enum In Array
```swift
enum Grade: String, ConvertibleEnum {
case perfect = "A"
case great = "B"
case good = "C"
case bad = "D"
}

struct Student: Convertible {
var name: String?
var grades: [Grade]?
}

let json: [String: Any] = [
"name": "Jack",
"grades": ["D", "B"]
]

let stu = json.kj.model(Student.self)
XCTAssert(stu.name == "Jack")
XCTAssert(stu.grades?[0] == .bad)
XCTAssert(stu.grades?[1] == .great)
```

### Enum In Dictionary
```swift
enum Grade: String, ConvertibleEnum {
case perfect = "A"
case great = "B"
case good = "C"
case bad = "D"
}

struct Student: Convertible {
var name: String?
var grades: [String: Grade]?
}

let json: [String: Any] = [
"name": "Jack",
"grades": ["2019": "D", "2020": "B"]
]

let stu = json.kj.model(Student.self)
XCTAssert(stu.name == "Jack")
XCTAssert(stu.grades?["2019"] == .bad)
XCTAssert(stu.grades?["2020"] == .great)
```

### Enum Array In Dictionary
```swift
enum Grade: String, ConvertibleEnum {
case perfect = "A"
case great = "B"
case good = "C"
case bad = "D"
}

struct Student: Convertible {
var name: String?
var grades: [String: [Grade?]]?
}

let json: [String: Any] = [
"name": "Jack",
"grades": ["2019": ["A", "B"], "2020": ["C", "D"]]
]

let stu = json.kj.model(Student.self)
XCTAssert(stu.name == "Jack")
XCTAssert(stu.grades?["2019"]?[0] == .perfect)
XCTAssert(stu.grades?["2019"]?[1] == .great)
XCTAssert(stu.grades?["2020"]?[0] == .good)
XCTAssert(stu.grades?["2020"]?[1] == .bad)
```

### Array
```swift
// Support conversion between Array\NSArray\NSMutableArray and Set\NSSet\NSMutableSet
Expand Down
Loading

0 comments on commit 88d8587

Please sign in to comment.