HandyJSON 如何在自定义属性映射的同时改变取值规则

vnzz0bqm  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(116)

如自定义映射规则范例中对parent的映射操作,假设需映射的json中该值的名称为parent_list, 我该如果同时描述两种映射规则?

deyfvvtc

deyfvvtc1#

func mapping(mapper: HelpingMapper) {
        mapper <<<
            self. parent <-- ["parent", "parent_list"]
}
zzoitvuj

zzoitvuj2#

func mapping(mapper: HelpingMapper) {
        mapper <<<
            self. parent <-- (["parent", "parent_list"], TransformOf<TypeA, TypeB>(fromJSON: { object_b -> TypeA in
                return TypeA.init(from: object_b)
            }, toJSON: { object_a -> TypeB in
                return TypeB.init(from: object_a)
            }))
}

相关问题