简体   繁体   English

使用两种JSON格式反序列化Mantle对象

[英]Deserialize Mantle object using two JSON formats

Is there a way to construct a mantle object using two different JSON objects? 有没有一种方法可以使用两个不同的JSON对象构造地幔对象? For example, say there is an Address class and the following two JSON formats: 例如,假设有一个Address类和以下两种JSON格式:

{
    "street: "s",
    "city" : "city",
    "state" : "state",
    "zipcode" "12345"
}

{
    "street_one: "s1",
    "street_two: "s2",
    "apartment" : "apt 1",
    "city" : "city",
    "state" : "state",
    "zip" "12345"
}

[MTLJSONAdapter modelOfClass:[Address class] fromJSONDictionary:JSONDictionary error:&error];

Is there somewhere in MTLJSONAdapter to recognize two formats and assign or serialize properties based on them? MTLJSONAdapter中是否有地方可以识别两种格式并基于它们分配或序列化属性?

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    if (isJsonV2) {
        // do new mapping
    }
    else {
        // do original mapping
    }
}

Hope to do something like above, or anything that allows conditionally mapping to the object. 希望做类似上面的事情,或者允许有条件地映射到对象的任何事情。

Mantle不支持此功能,但是您可以为V2使用具有额外街道入口的子类,或者使用协议封装共享行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM