tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.14k stars 1.03k forks source link

Does it support wildcard path? #1072

Closed maimake closed 5 years ago

maimake commented 5 years ago

I wanna map array from something like this

values <- map["nested.*.item"]

Does it support wildcard path?

Your JSON dictionary:

{
    "nested": [
        {
            "id": 1,
            "item": {
                "value": 1
            }
        },
        {
            "id": 2,
            "item": {
                "value": 2
            }
        },
        {
            "id": 3,
            "item": {
                "value": 3
            }
        }
    ]
}

Your model:

struct Item: Mappable {
    var value: Int?

    init?(map: Map){

    }

    mutating func mapping(map: Map) {
        value <- map["value"]
    }
}
struct Repo: Mappable {
    var values: [Item]?

    init?(map: Map){

    }

    mutating func mapping(map: Map) {
        values <- map["nested.*.item"]
    }
}

What you did:

let repo = Mapper<Repo>().map(myJSONDictionary)

What you expected:

I exepected something like:

Repo(values: [Item(value:1),Item(value:2),Item(value:3)])

What you got:

Repo(values: nil)  
tristanhimmelman commented 5 years ago

No unfortunately we don't support wildcard arguments at this time.