 	}
 	
 	
+	// MARK: Attributes
+
+	/**
+	 Extracts the attributes from the given data into the given resource.
+
+	 This method loops over all the attributes in the passed resource, maps the attribute name
+	 to the key for the serialized form and invokes `extractAttribute`. It then formats the extracted
+	 attribute and sets the formatted value on the resource.
+
+	 :param: serializedData The data from which to extract the attributes.
+	 :param: resource       The resource into which to extract the attributes.
+	 */
+	private func extractAttributes(serializedData: JSONValue, intoResource resource: Resource) {
+		for (attributeName, attribute) in resource.persistentAttributes {
+			if attribute.isRelationship() {
+				continue
+			}
+			
+			let key = attribute.representationName ?? attributeName
+			
+			if let extractedValue: AnyObject = self.extractAttribute(serializedData, key: key) {
+				let formattedValue: AnyObject = self.formatter.deserialize(extractedValue, ofType: attribute.type)
+				resource.setValue(formattedValue, forKey: attributeName)
+			}
+		}
+	}
+	
+	/**
+	 Extracts the value for the given key from the passed serialized data.
+
+	 :param: serializedData The data from which to extract the attribute.
+	 :param: key            The key for which to extract the value from the data.
+
+	 :returns: The extracted value or nil if no attribute with the given key was found in the data.
+	 */
+	private func extractAttribute(serializedData: JSONValue, key: String) -> AnyObject? {
+		if let value: AnyObject = serializedData[key].any {
+			return value
+		}
+		
+		return nil
+	}
+	
+	
+	// MARK: Relationships
+	
+	/**
+	 Extracts the relationships from the given data into the given resource.
+
+	 This method loops over all the relationships in the passed resource, maps the relationship name
+	 to the key for the serialized form and invokes `extractToOneRelationship` or `extractToManyRelationship`.
+	 It then sets the extracted ResourceRelationship on the resource.
+
+	 :param: serializedData The data from which to extract the relationships.
+	 :param: resource       The resource into which to extract the relationships.
+	 */
+	private func extractRelationships(serializedData: JSONValue, intoResource resource: Resource) {
+		for (attributeName, attribute) in resource.persistentAttributes {
+			if !attribute.isRelationship() {
+				continue
+			}
+			
+			let key = attribute.representationName ?? attributeName
+			
+			switch attribute.type {
+			case .ToOne:
+				if let extractedRelationship = self.extractToOneRelationship(serializedData, key: key, resource: resource) {
+					resource.links[attributeName] = extractedRelationship
+				}
+			case .ToMany:
+				if let extractedRelationship = self.extractToManyRelationship(serializedData, key: key, resource: resource) {
+					resource.links[attributeName] = extractedRelationship
+				}
+			default: ()
+			}
+		}
+	}
+	
+	/**
+	 Extracts the to-one relationship for the given key from the passed serialized data.
+	 
+	 This method supports both the single ID form and the resource object forms.
+	
+	 :param: serializedData The data from which to extract the relationship.
+	 :param: key            The key for which to extract the relationship from the data.
+	
+	 :returns: The extracted relationship or nil if no relationship with the given key was found in the data.
+	*/
+	private func extractToOneRelationship(serializedData: JSONValue, key: String, resource: Resource) -> ResourceLink? {
+		// Single ID form
+		if let ID = serializedData["links"][key].string {
+			return ResourceLink(href: nil, ID: ID, type: nil)
+		}
+		
+		// Resource object form
+		else if let linkData = serializedData["links"][key].object {
+			var href: String?, ID: String?, type: String?
+			
+			if linkData["href"] != nil {
+				href = linkData["href"]!.string
+			}
+			
+			if linkData["id"] != nil {
+				ID = linkData["id"]!.string
+			}
+			
+			if linkData["type"] != nil {
+				type = linkData["type"]!.string
+			}
+			
+			return ResourceLink(href: href, ID: ID, type: type)
+		}
+		
+		return nil
+	}
+	
+	/**
+	 Extracts the to-many relationship for the given key from the passed serialized data.
+	
+	 This method supports both the array of IDs form and the resource object forms.
+	
+	 :param: serializedData The data from which to extract the relationship.
+	 :param: key            The key for which to extract the relationship from the data.
+	
+	 :returns: The extracted relationship or nil if no relationship with the given key was found in the data.
+	*/
+	private func extractToManyRelationship(serializedData: JSONValue, key: String, resource: Resource) -> ResourceLink? {
+		// ID array form
+		if let IDs = serializedData["links"][key].array {
+			return ResourceLink(href: nil, IDs: IDs.map { return $0.string! }, type: nil)
+		}
+		
+		// Resource object form
+		else if let linkData = serializedData["links"][key].object {
+			var href: String?, IDs: [String]?, type: String?
+			
+			if linkData["href"] != nil {
+				href = linkData["href"]!.string
+			}
+			
+			if linkData["ids"] != nil {
+				IDs = linkData["ids"]!.array!.map { return $0.string! }
+			}
+			
+			if linkData["type"] != nil {
+				type = linkData["type"]!.string
+			}
+		
+			return ResourceLink(href: href, IDs: IDs, type: type)
+		}
+		
+		return nil
+	}
+	
+	/**
+	 Resolves the relations of the resources in the store.
+	*/
+	private func resolveRelations() {
+		for resource in self.store.allResources() {
+			
+			for (linkName: String, link: ResourceLink) in resource.links {
+				let type = link.type ?? linkName
+				
+				if resource.persistentAttributes[linkName]!.type == ResourceAttribute.AttributeType.ToOne {
+					
+					// We can only resolve if an ID is known
+					if let ID = link.IDs?.first {
+
+						// Find target of relation in store
+						if let targetResource = store.resource(type, identifier: ID) {
+							resource.setValue(targetResource, forKey: linkName)
+						} else {
+							// Target resource was not found in store, create a placeholder
+							let placeholderResource = self.classMap[type]() as Resource
+							placeholderResource.resourceID = ID
+							resource.setValue(placeholderResource, forKey: linkName)
+						}
+					}
+				
+				} else if resource.persistentAttributes[linkName]!.type == ResourceAttribute.AttributeType.ToMany {
+					var targetResources: [Resource] = []
+					
+					// We can only resolve if IDs are known
+					if let IDs = link.IDs {
+
+						for ID in IDs {
+							// Find target of relation in store
+							if let targetResource = store.resource(type, identifier: ID) {
+								targetResources.append(targetResource)
+							} else {
+								// Target resource was not found in store, create a placeholder
+								let placeholderResource = self.classMap[type]() as Resource
+								placeholderResource.resourceID = ID
+								targetResources.append(placeholderResource)
+							}
+							
+							resource.setValue(targetResources, forKey: linkName)
+						}
+					}
+				}
+			}
+		}
+	}
+	
+	
 	// MARK: Links
 	
-	private func extractLinks(serializedData: JSONValue) {
-		if let links = serializedData["links"].object {
-
+	/**
+	Extracts the top level links from the serialized data.
+	
+	Each extracted link is added the associated resources in on the following ways:
+	- If the associated resource already contains a link for the given relation,
+	the existing link is interpolated and merged with data from the top level link.
+	Data on the existing link has precedence over the top level data.
+	- If the ssociated resource does not contain a link for the given relation,
+	the top level link is added to the resource after interpolation.
+	*/
+	private func extractLinks() {
+		if let links = self.data["links"].object {
+			
 			// Loop through all links in the serialized data
 			for (linkName, linkData) in links {
 				let linkTemplate = LinkTemplate(compoundKey: linkName, href: linkData["href"].string, type: linkData["type"].string)

			}
		}
		
		self.extractLinks(self.data)
	
		self.resolveRelations()
		
		self.result = DeserializationResult(self.store, nil)

			}
		}
	}
}


