// Autogenerated `SwiftReflector` @ 2015-07-24 09:44:25 +0000

import Foundation

// Plan

// Json for Plan

extension Plan : JsonConvertable { 
    static func parseJson(json: AnyObject) throws -> Plan { 
        let isItGood: Optional<Bool> = try Json.deserialize(json, "isItGood")
        let goals: Array<String> = try Json.deserialize(json, "goals")
        let chanceOfSuccess: Float = try Json.deserialize(json, "chanceOfSuccess")
        return Plan(
            isItGood: isItGood,
            goals: goals,
            chanceOfSuccess: chanceOfSuccess
         )
    }
    
    func toJson() -> AnyObject { 
        return [
            "isItGood" : isItGood?.toJson() ?? NSNull(),
            "goals" : goals.toJson(),
            "chanceOfSuccess" : chanceOfSuccess.toJson()
         ]
    }
}

// DuckType

// Json for DuckType

extension DuckType { 
    func toJson() -> AnyObject { 
        return [
            "name" : name.toJson(),
            "rank" : rank.toJson(),
            "age" : age.toJson(),
            "spouse" : spouse?.toJson() ?? NSNull(),
            "plansForFuture" : plansForFuture.toJson(),
            "personality" : personality.toJson()
         ]
    }
}

extension Json { 
    static func deserialize(json: AnyObject) throws -> DuckType { 
        let name: String = try Json.deserialize(json, "name")
        let rank: String = try Json.deserialize(json, "rank")
        let age: Int = try Json.deserialize(json, "dateOfBirth")
        let spouse: Optional<DuckType> = try Json.deserialize(json, "spouse")
        let plansForFuture: Array<Plan> = try Json.deserialize(json, "plansForFuture")
        let personality: PersonalityType = try Json.deserialize(json, "personality")
        return Duck(
            name: name,
            rank: rank,
            age: age,
            spouse: spouse,
            plansForFuture: plansForFuture,
            personality: personality
         )
    }
    
    static func deserialize(json: AnyObject, _ path: String) throws -> DuckType? { 
        if let value = try Json.valueAtPath(json, path) { 
            return try Json.deserialize(value)
        }
        else { 
            return nil
        }
    }
    static func deserialize(json: AnyObject, _ path: String) throws -> DuckType { 
        let result: DuckType? = try Json.deserialize(json, path)
        guard let result2 = result else { 
            throw NSError(
                domain: JsonParsingDomain,
                code: JsonParsingError.MemberDoesntExist.rawValue,
                userInfo: [
                      JsonParsingTargetKey: json,
                      JsonParsingTargetPathKey: path
                  ])
        }
        return result2
    }
    static func deserialize(json: AnyObject, _ path: String) throws ->[DuckType] { 
        return try Json.deserialize(json, path, Json.deserialize)
    }
}

// PersonalityType

// Json for PersonalityType

extension PersonalityType { 
    func toJson() -> AnyObject { 
        return [
            "isFun" : isFun.toJson(),
            "isSafeFlyer" : isSafeFlyer.toJson(),
            "isAlphaDuck" : isAlphaDuck.toJson()
         ]
    }
}

extension Json { 
    static func deserialize(json: AnyObject) throws -> PersonalityType { 
        let isFun: Bool = try Json.deserialize(json, "isFun")
        let isSafeFlyer: Bool = try Json.deserialize(json, "isSafeFlyer")
        let isAlphaDuck: Bool = try Json.deserialize(json, "duckCaptain")
        return Personality(
            isFun: isFun,
            isSafeFlyer: isSafeFlyer,
            isAlphaDuck: isAlphaDuck
         )
    }
    
    static func deserialize(json: AnyObject, _ path: String) throws -> PersonalityType? { 
        if let value = try Json.valueAtPath(json, path) { 
            return try Json.deserialize(value)
        }
        else { 
            return nil
        }
    }
    static func deserialize(json: AnyObject, _ path: String) throws -> PersonalityType { 
        let result: PersonalityType? = try Json.deserialize(json, path)
        guard let result2 = result else { 
            throw NSError(
                domain: JsonParsingDomain,
                code: JsonParsingError.MemberDoesntExist.rawValue,
                userInfo: [
                      JsonParsingTargetKey: json,
                      JsonParsingTargetPathKey: path
                  ])
        }
        return result2
    }
    static func deserialize(json: AnyObject, _ path: String) throws ->[PersonalityType] { 
        return try Json.deserialize(json, path, Json.deserialize)
    }
}


