{"action":"opened","issue":{"url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/790","repository_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper","labels_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/790/labels{/name}","comments_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/790/comments","events_url":"https://api.github.com/repos/Hearst-DD/ObjectMapper/issues/790/events","html_url":"https://github.com/Hearst-DD/ObjectMapper/issues/790","id":218769449,"number":790,"title":"Recursion not mapping nested children with same / similar structure as parent","user":{"login":"pkasson","id":3072247,"avatar_url":"https://avatars2.githubusercontent.com/u/3072247?v=3","gravatar_id":"","url":"https://api.github.com/users/pkasson","html_url":"https://github.com/pkasson","followers_url":"https://api.github.com/users/pkasson/followers","following_url":"https://api.github.com/users/pkasson/following{/other_user}","gists_url":"https://api.github.com/users/pkasson/gists{/gist_id}","starred_url":"https://api.github.com/users/pkasson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pkasson/subscriptions","organizations_url":"https://api.github.com/users/pkasson/orgs","repos_url":"https://api.github.com/users/pkasson/repos","events_url":"https://api.github.com/users/pkasson/events{/privacy}","received_events_url":"https://api.github.com/users/pkasson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-02T14:53:21Z","updated_at":"2017-04-02T14:53:21Z","closed_at":null,"body":"### Your JSON dictionary:\r\n\r\n```json\r\n{\r\n  \"key_diagnostic_stage\" : \"source.diagnostic.stage.swift.parse\",\r\n  \"key_substructure\" : [\r\n    {\r\n      \"key_bodylength\" : 293,\r\n      \r\n      \"key_nameoffset\" : 64,\r\n      \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n      \r\n      \"key_substructure\" : [\r\n        {\r\n          \"key_nameoffset\" : 77,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_length\" : 16,\r\n          \"key_name\" : \"intX\",\r\n          \"key_kind\" : \"source.lang.swift.decl.var.instance\",\r\n          \"key_namelength\" : 4,\r\n          \"key_offset\" : 73\r\n        },\r\n        {\r\n          \"key_nameoffset\" : 96,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_length\" : 23,\r\n          \"key_name\" : \"stringY\",\r\n          \"key_kind\" : \"source.lang.swift.decl.var.instance\",\r\n          \"key_namelength\" : 7,\r\n          \"key_offset\" : 92\r\n        },\r\n        {\r\n          \"key_nameoffset\" : 122,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_length\" : 21,\r\n          \"key_name\" : \"dateWork\",\r\n          \"key_kind\" : \"source.lang.swift.decl.var.instance\",\r\n          \"key_namelength\" : 8,\r\n          \"key_offset\" : 118\r\n        },\r\n        {\r\n          \"key_offset\" : 133,\r\n          \"key_nameoffset\" : 133,\r\n          \"key_length\" : 6,\r\n          \"key_name\" : \"Date\",\r\n          \"key_bodyoffset\" : 138,\r\n          \"key_kind\" : \"source.lang.swift.expr.call\",\r\n          \"key_namelength\" : 4,\r\n          \"key_bodylength\" : 0\r\n        },\r\n        {\r\n          \"key_bodylength\" : 32,\r\n          \"key_nameoffset\" : 148,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_substructure\" : [\r\n            {\r\n              \"key_bodylength\" : 20,\r\n              \"key_nameoffset\" : 164,\r\n              \"key_substructure\" : [\r\n                {\r\n                  \"key_offset\" : 182,\r\n                  \"key_nameoffset\" : 182,\r\n                  \"key_length\" : 6,\r\n                  \"key_name\" : \"Date\",\r\n                  \"key_bodyoffset\" : 187,\r\n                  \"key_kind\" : \"source.lang.swift.expr.call\",\r\n                  \"key_namelength\" : 4,\r\n                  \"key_bodylength\" : 0\r\n                }\r\n              ],\r\n              \"key_length\" : 27,\r\n              \"key_name\" : \"print\",\r\n              \"key_bodyoffset\" : 170,\r\n              \"key_kind\" : \"source.lang.swift.expr.call\",\r\n              \"key_offset\" : 164,\r\n              \"key_namelength\" : 5\r\n            }\r\n          ],\r\n          \"key_length\" : 51,\r\n          \"key_name\" : \"showDate()\",\r\n          \"key_bodyoffset\" : 161,\r\n          \"key_kind\" : \"source.lang.swift.decl.function.method.instance\",\r\n          \"key_offset\" : 143,\r\n          \"key_namelength\" : 10\r\n        },\r\n        {\r\n          \"key_bodylength\" : 34,\r\n          \"key_nameoffset\" : 203,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_substructure\" : [\r\n            {\r\n              \"key_nameoffset\" : 214,\r\n              \"key_typename\" : \"String\",\r\n              \"key_length\" : 12,\r\n              \"key_name\" : \"text\",\r\n              \"key_kind\" : \"source.lang.swift.decl.var.parameter\",\r\n              \"key_namelength\" : 4,\r\n              \"key_offset\" : 214\r\n            },\r\n            {\r\n              \"key_offset\" : 233,\r\n              \"key_nameoffset\" : 233,\r\n              \"key_length\" : 29,\r\n              \"key_name\" : \"print\",\r\n              \"key_bodyoffset\" : 239,\r\n              \"key_kind\" : \"source.lang.swift.expr.call\",\r\n              \"key_namelength\" : 5,\r\n              \"key_bodylength\" : 22\r\n            }\r\n          ],\r\n          \"key_length\" : 67,\r\n          \"key_name\" : \"helloWorld(text:)\",\r\n          \"key_bodyoffset\" : 230,\r\n          \"key_kind\" : \"source.lang.swift.decl.function.method.instance\",\r\n          \"key_offset\" : 198,\r\n          \"key_namelength\" : 24\r\n        },\r\n        {\r\n          \"key_bodylength\" : 69,\r\n          \"key_nameoffset\" : 274,\r\n          \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n          \"key_substructure\" : [\r\n            {\r\n              \"key_offset\" : 333,\r\n              \"key_nameoffset\" : 333,\r\n              \"key_length\" : 24,\r\n              \"key_name\" : \"print\",\r\n              \"key_bodyoffset\" : 339,\r\n              \"key_kind\" : \"source.lang.swift.expr.call\",\r\n              \"key_namelength\" : 5,\r\n              \"key_bodylength\" : 17\r\n            }\r\n          ],\r\n          \"key_length\" : 92,\r\n          \"key_name\" : \"doSimpleCalc()\",\r\n          \"key_bodyoffset\" : 291,\r\n          \"key_kind\" : \"source.lang.swift.decl.function.method.instance\",\r\n          \"key_offset\" : 269,\r\n          \"key_namelength\" : 14\r\n        }\r\n      ],\r\n      \r\n      \"key_length\" : 306,\r\n      \"key_runtime_name\" : \"_TtC8__main__4Test\",\r\n      \"key_name\" : \"Test\",\r\n      \"key_bodyoffset\" : 70,\r\n      \"key_kind\" : \"source.lang.swift.decl.class\",\r\n      \"key_offset\" : 58,\r\n      \"key_namelength\" : 4\r\n    },\r\n    {\r\n      \"key_nameoffset\" : 401,\r\n      \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n      \"key_length\" : 17,\r\n      \"key_name\" : \"test\",\r\n      \"key_kind\" : \"source.lang.swift.decl.var.global\",\r\n      \"key_namelength\" : 4,\r\n      \"key_offset\" : 397\r\n    },\r\n    {\r\n      \"key_offset\" : 408,\r\n      \"key_nameoffset\" : 408,\r\n      \"key_length\" : 6,\r\n      \"key_name\" : \"Test\",\r\n      \"key_bodyoffset\" : 413,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\",\r\n      \"key_namelength\" : 4,\r\n      \"key_bodylength\" : 0\r\n    },\r\n    {\r\n      \"key_offset\" : 416,\r\n      \"key_nameoffset\" : 416,\r\n      \"key_length\" : 15,\r\n      \"key_name\" : \"test.showDate\",\r\n      \"key_bodyoffset\" : 430,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\",\r\n      \"key_namelength\" : 13,\r\n      \"key_bodylength\" : 0\r\n    },\r\n    {\r\n      \"key_bodylength\" : 14,\r\n      \"key_nameoffset\" : 432,\r\n      \"key_substructure\" : [\r\n        {\r\n          \"key_offset\" : 448,\r\n          \"key_nameoffset\" : 448,\r\n          \"key_length\" : 14,\r\n          \"key_name\" : \"text\",\r\n          \"key_bodyoffset\" : 454,\r\n          \"key_kind\" : \"source.lang.swift.expr.argument\",\r\n          \"key_namelength\" : 4,\r\n          \"key_bodylength\" : 8\r\n        }\r\n      ],\r\n      \"key_length\" : 31,\r\n      \"key_name\" : \"test.helloWorld\",\r\n      \"key_bodyoffset\" : 448,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\",\r\n      \"key_offset\" : 432,\r\n      \"key_namelength\" : 15\r\n    },\r\n    {\r\n      \"key_offset\" : 464,\r\n      \"key_nameoffset\" : 464,\r\n      \"key_length\" : 19,\r\n      \"key_name\" : \"test.doSimpleCalc\",\r\n      \"key_bodyoffset\" : 482,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\",\r\n      \"key_namelength\" : 17,\r\n      \"key_bodylength\" : 0\r\n    }\r\n  ],\r\n  \"key_offset\" : 0,\r\n  \"key_length\" : 486\r\n}\r\n```\r\n\r\nI generated this model using 'SwiftyJSONAccelerator' and aside from missing a few items, including the recursion children, it looked ok, but I added a few attributes\r\n\r\n### Your model:\r\n\r\n```swift\r\n\r\n\r\nimport Foundation\r\nimport ObjectMapper\r\n\r\npublic final class KT2KeySubstructure: Mappable, NSCoding\r\n{\r\n\r\n  // MARK: Declaration for string constants to be used to decode and also serialize.\r\n  private struct SerializationKeys\r\n  {\r\n    static let keySubstructure  = \"key_substructure\"                   // 20170402 - hopefully this fixes the non recursion issue\r\n\r\n    static let keyBodylength    = \"key_bodylength\"\r\n    static let keyRunTimeName   = \"key_runtime_name\"\r\n    static let keyBodyOffset    = \"key_bodyoffset\"\r\n\r\n    static let keyNamelength    = \"key_namelength\"\r\n    static let keyAccessibility = \"key_accessibility\"\r\n    static let keyLength        = \"key_length\"\r\n    static let keyName          = \"key_name\"\r\n    static let keyNameoffset    = \"key_nameoffset\"\r\n    static let keyOffset        = \"key_offset\"\r\n    static let keyKind          = \"key_kind\"\r\n  }\r\n\r\n \r\n  // MARK: Properties\r\n  public var keySubstructure : KT2KeySubstructure?                     // 20170402 - added manually the next 4\r\n  public var keyBodylength   : Int?\r\n  public var keyBodyOffset   : Int?\r\n  public var keyRunTimeName  : String?\r\n \r\n  public var keyNamelength   : Int?\r\n  public var keyAccessibility: String?\r\n  public var keyLength       : Int?\r\n  public var keyName         : String?\r\n  public var keyNameoffset   : Int?\r\n  public var keyOffset       : Int?\r\n  public var keyKind         : String?\r\n\r\n \r\n  // MARK: ObjectMapper Initializers\r\n  /// Map a JSON object to this class using ObjectMapper.\r\n  ///\r\n  /// - parameter map: A mapping from ObjectMapper.\r\n  public required init?(map: Map)\r\n  {\r\n   print(map)\r\n  }\r\n\r\n  /// Map a JSON object to this class using ObjectMapper.\r\n  ///\r\n  /// - parameter map: A mapping from ObjectMapper.\r\n  public func mapping(map: Map)\r\n  {\r\n    keySubstructure  <- map[SerializationKeys.keySubstructure]         // 20170402 - added manually the next\r\n   \r\n    keyBodylength    <- map[SerializationKeys.keyBodylength]\r\n    keyBodyOffset    <- map[SerializationKeys.keyBodyOffset]\r\n    keyRunTimeName   <- map[SerializationKeys.keyRunTimeName]\r\n \r\n    keyNamelength    <- map[SerializationKeys.keyNamelength]\r\n    keyAccessibility <- map[SerializationKeys.keyAccessibility]\r\n    keyLength        <- map[SerializationKeys.keyLength]\r\n    keyName          <- map[SerializationKeys.keyName]\r\n    keyNameoffset    <- map[SerializationKeys.keyNameoffset]\r\n    keyOffset        <- map[SerializationKeys.keyOffset]\r\n    keyKind          <- map[SerializationKeys.keyKind]\r\n  }\r\n\r\n \r\n  /// Generates description of the object in the form of a NSDictionary.\r\n  ///\r\n  /// - returns: A Key value pair containing all valid values in the object.\r\n  public func dictionaryRepresentation() -> [String: Any]\r\n  {\r\n    var dictionary: [String: Any] = [:]\r\n\r\n    if let value = keySubstructure  { dictionary[SerializationKeys.keySubstructure]  = value }\r\n\r\n    if let value = keyBodylength    { dictionary[SerializationKeys.keyBodylength]    = value }\r\n    if let value = keyBodyOffset    { dictionary[SerializationKeys.keyBodyOffset]    = value }\r\n    if let value = keyRunTimeName   { dictionary[SerializationKeys.keyRunTimeName]   = value }\r\n\r\n    if let value = keyNamelength    { dictionary[SerializationKeys.keyNamelength]    = value }\r\n    if let value = keyAccessibility { dictionary[SerializationKeys.keyAccessibility] = value }\r\n    if let value = keyLength        { dictionary[SerializationKeys.keyLength]        = value }\r\n    if let value = keyName          { dictionary[SerializationKeys.keyName]          = value }\r\n    if let value = keyNameoffset    { dictionary[SerializationKeys.keyNameoffset]    = value }\r\n    if let value = keyOffset        { dictionary[SerializationKeys.keyOffset]        = value }\r\n    if let value = keyKind          { dictionary[SerializationKeys.keyKind]          = value }\r\n   \r\n   return dictionary\r\n  }\r\n\r\n \r\n  // MARK: NSCoding Protocol\r\n  required public init(coder aDecoder: NSCoder)\r\n  {\r\n    self.keySubstructure  = aDecoder.decodeObject(forKey: SerializationKeys.keySubstructure)  as? KT2KeySubstructure\r\n   \r\n    self.keyBodylength    = aDecoder.decodeObject(forKey: SerializationKeys.keyBodylength)    as? Int\r\n    self.keyBodyOffset    = aDecoder.decodeObject(forKey: SerializationKeys.keyBodyOffset)    as? Int\r\n    self.keyRunTimeName   = aDecoder.decodeObject(forKey: SerializationKeys.keyRunTimeName)   as? String\r\n\r\n   \r\n    self.keyNamelength    = aDecoder.decodeObject(forKey: SerializationKeys.keyNamelength)    as? Int\r\n    self.keyAccessibility = aDecoder.decodeObject(forKey: SerializationKeys.keyAccessibility) as? String\r\n    self.keyLength        = aDecoder.decodeObject(forKey: SerializationKeys.keyLength)        as? Int\r\n    self.keyName          = aDecoder.decodeObject(forKey: SerializationKeys.keyName)          as? String\r\n    self.keyNameoffset    = aDecoder.decodeObject(forKey: SerializationKeys.keyNameoffset)    as? Int\r\n    self.keyOffset        = aDecoder.decodeObject(forKey: SerializationKeys.keyOffset)        as? Int\r\n    self.keyKind          = aDecoder.decodeObject(forKey: SerializationKeys.keyKind)          as? String\r\n  }\r\n\r\n \r\n  public func encode(with aCoder: NSCoder)\r\n  {\r\n    aCoder.encode(keySubstructure,  forKey: SerializationKeys.keySubstructure)\r\n\r\n    aCoder.encode(keyBodylength,    forKey: SerializationKeys.keyBodylength)\r\n    aCoder.encode(keyBodyOffset,    forKey: SerializationKeys.keyBodyOffset)\r\n    aCoder.encode(keyRunTimeName,   forKey: SerializationKeys.keyRunTimeName)\r\n   \r\n    aCoder.encode(keyNamelength,    forKey: SerializationKeys.keyNamelength)\r\n    aCoder.encode(keyAccessibility, forKey: SerializationKeys.keyAccessibility)\r\n    aCoder.encode(keyLength,        forKey: SerializationKeys.keyLength)\r\n    aCoder.encode(keyName,          forKey: SerializationKeys.keyName)\r\n    aCoder.encode(keyNameoffset,    forKey: SerializationKeys.keyNameoffset)\r\n    aCoder.encode(keyOffset,        forKey: SerializationKeys.keyOffset)\r\n    aCoder.encode(keyKind,          forKey: SerializationKeys.keyKind)\r\n  }\r\n\r\n}\r\n\r\n\r\n```\r\n\r\n### What you did:\r\n\r\n```swift\r\n  \r\n  let payload = Mapper<KT2Repository>().map(JSONString: json)      // 20160929\r\n  \r\n  return payload!\r\n```\r\n\r\n### What you expected:\r\n\r\nI expected something like:\r\n\r\nI expected that the nested children, whose structure matches the parent 95%, would handle the recursion properly, but it didn't.  It did everything ok EXCEPT recursion\r\n\r\n### What you got:\r\n\r\n```json\r\n{\r\n  \"key_length\" : 486,\r\n  \"key_diagnostic_stage\" : \"source.diagnostic.stage.swift.parse\",\r\n  \"key_offset\" : 0,\r\n  \"key_substructure\" : [\r\n    {\r\n      \"key_runtime_name\" : \"_TtC8__main__4Test\",\r\n      \"key_namelength\" : 4,\r\n      \"key_length\" : 306,\r\n      \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n      \"key_bodyoffset\" : 70,\r\n      \"key_name\" : \"Test\",\r\n      \"key_bodylength\" : 293,\r\n      \"key_nameoffset\" : 64,\r\n      \"key_offset\" : 58,\r\n      \"key_kind\" : \"source.lang.swift.decl.class\"\r\n    },\r\n    {\r\n      \"key_namelength\" : 4,\r\n      \"key_accessibility\" : \"source.lang.swift.accessibility.internal\",\r\n      \"key_length\" : 17,\r\n      \"key_name\" : \"test\",\r\n      \"key_nameoffset\" : 401,\r\n      \"key_offset\" : 397,\r\n      \"key_kind\" : \"source.lang.swift.decl.var.global\"\r\n    },\r\n    {\r\n      \"key_namelength\" : 4,\r\n      \"key_length\" : 6,\r\n      \"key_bodyoffset\" : 413,\r\n      \"key_name\" : \"Test\",\r\n      \"key_bodylength\" : 0,\r\n      \"key_nameoffset\" : 408,\r\n      \"key_offset\" : 408,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\"\r\n    },\r\n    {\r\n      \"key_namelength\" : 13,\r\n      \"key_length\" : 15,\r\n      \"key_bodyoffset\" : 430,\r\n      \"key_name\" : \"test.showDate\",\r\n      \"key_bodylength\" : 0,\r\n      \"key_nameoffset\" : 416,\r\n      \"key_offset\" : 416,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\"\r\n    },\r\n    {\r\n      \"key_namelength\" : 15,\r\n      \"key_length\" : 31,\r\n      \"key_bodyoffset\" : 448,\r\n      \"key_name\" : \"test.helloWorld\",\r\n      \"key_bodylength\" : 14,\r\n      \"key_nameoffset\" : 432,\r\n      \"key_offset\" : 432,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\"\r\n    },\r\n    {\r\n      \"key_namelength\" : 17,\r\n      \"key_length\" : 19,\r\n      \"key_bodyoffset\" : 482,\r\n      \"key_name\" : \"test.doSimpleCalc\",\r\n      \"key_bodylength\" : 0,\r\n      \"key_nameoffset\" : 464,\r\n      \"key_offset\" : 464,\r\n      \"key_kind\" : \"source.lang.swift.expr.call\"\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\n"}}
{"actor":{"display_login":"pkasson"}}