Skip to content

Commit 654d787

Browse files
authored
Merge pull request #25 from luoxiu/test-best-match
add test testComplex_JSONKeyWithDot_bestMatch
2 parents 49e8a3f + c8dcbe4 commit 654d787

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

KakaJSONTests/JSON_To_Model/JTM_05_KeyMapping.swift

+25
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,31 @@ class JTM_05_KeyMapping: XCTestCase {
259259
XCTAssert(team.captainName == captainName)
260260
}
261261

262+
func testComplex_JSONKeyWithDot_bestMatch() {
263+
struct Model: Convertible {
264+
var valueA: String?
265+
var valueB: String?
266+
267+
func kj_modelKey(from property: Property) -> ModelPropertyKey {
268+
switch property.name {
269+
case "valueA": return "a.0.a"
270+
case "valueB": return "b.0.b.0.b"
271+
default: return property.name
272+
}
273+
}
274+
}
275+
276+
let json: [String: Any] = [
277+
"a": [ "l", "u", "o" ],
278+
"b": [
279+
[ "b": [ "x", "i", "u" ] ]
280+
]
281+
]
282+
let model = json.kj.model(Model.self)
283+
XCTAssert(model.valueA == "l")
284+
XCTAssert(model.valueB == "x")
285+
}
286+
262287
func testConfig1() {
263288
// Global Config
264289
ConvertibleConfig.setModelKey { property in

0 commit comments

Comments
 (0)