             if relationship.isToMany {
                 var children: Any?
                 if keyName.contains(".") {
-                    if let deepMappingRootkey = keyName.components(separatedBy: ".").first {
-                        if let rootObject = dictionary[deepMappingRootkey] as? [String: Any] {
-                            if let deepMappingLeaveKey = keyName.components(separatedBy: ".").last {
-                                children = rootObject[deepMappingLeaveKey]
-                            }
-                        }
+                    var rootObject: [String: Any]? = dictionary
+                    let deepMappingKeys = keyName.split(separator: ".").map { String($0)}
+                    let keyComponents = deepMappingKeys[0...deepMappingKeys.count - 2]
+                    
+                    for key in keyComponents {
+                        rootObject = rootObject?[key] as? [String: Any]
+                    }
+                    
+                    if let innerObject = rootObject, let deepMappingLeaveKey = deepMappingKeys.last {
+                        children = innerObject[deepMappingLeaveKey]
                     }
                 } else {
                     children = dictionary[keyName]


                var child: Any?
                if keyName.contains(".") {
                    if let deepMappingRootkey = keyName.components(separatedBy: ".").first {
                        if let rootObject = dictionary[deepMappingRootkey] as? [String: Any] {
                            if let deepMappingLeaveKey = keyName.components(separatedBy: ".").last {
                                child = rootObject[deepMappingLeaveKey]
                            }
                        }
                    }
                } else {
                    child = dictionary[keyName]


        if let customRelationshipName = relationship.customKey {
            if customRelationshipName.contains(".") {
                var rootObject: [String: Any]? = dictionary
                let deepMappingKeys = customRelationshipName.split(separator: ".").map { String($0)}
                let keyComponents = deepMappingKeys[0...deepMappingKeys.count - 2]
                
                for key in keyComponents {
                    rootObject = rootObject?[key] as? [String: Any]
                }
                
                if let innerObject = rootObject, let deepMappingLeaveKey = deepMappingKeys.last {
                    filteredObjectDictionary = innerObject[deepMappingLeaveKey] as? [String: Any]
                    jsonContainsRelationship = innerObject[deepMappingLeaveKey] != nil
                }
            } else {
                filteredObjectDictionary = dictionary[customRelationshipName] as? [String: Any]
