JSON Modeler Code Examples

The following are usable Swift (with Core Data) classes from the Stripe List Customers API
//
//	Metadata.swift
//	Model file Generated using JSON Modeler: http://www.jbsolutions.net/json-modeler

import Foundation
import CoreData

class Metadata : NSManagedObject {

	@NSManaged var data : Data!


	/**
	 * Instantiate the instance using the passed dictionary values to set the properties values
	 */
	init(fromDictionary dictionary: NSDictionary, context: NSManagedObjectContext)	{
		let entity = NSEntityDescription.entityForName("Metadata", inManagedObjectContext: context)!
		super.init(entity: entity, insertIntoManagedObjectContext: context)
		if let dataData = dictionary["data"] as? NSDictionary{
			data = Data(fromDictionary: dataData, context:context)
		}
	}

	/**
	 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
	 */
	func toDictionary() -> NSDictionary
	{
		var dictionary = NSMutableDictionary()
		if data != nil{
			dictionary["data"] = data.toDictionary()
		}
		return dictionary
	}

}
//
//	Data.swift
//	Model file Generated using JSON Modeler: http://www.jbsolutions.net/json-modeler

import Foundation
import CoreData

class Data : NSManagedObject {

	@NSManaged var source : Source!
	@NSManaged var addressCity : AnyObject!
	@NSManaged var addressCountry : AnyObject!
	@NSManaged var addressLine1 : AnyObject!
	@NSManaged var addressLine1Check : AnyObject!
	@NSManaged var addressLine2 : AnyObject!
	@NSManaged var addressState : AnyObject!
	@NSManaged var addressZip : AnyObject!
	@NSManaged var addressZipCheck : AnyObject!
	@NSManaged var brand : String!
	@NSManaged var country : String!
	@NSManaged var customer : String!
	@NSManaged var cvcCheck : String!
	@NSManaged var dynamicLast4 : AnyObject!
	@NSManaged var expMonth : Int
	@NSManaged var expYear : Int
	@NSManaged var fingerprint : String!
	@NSManaged var funding : String!
	@NSManaged var id : String!
	@NSManaged var last4 : String!
	@NSManaged var metadata : Metadata!
	@NSManaged var name : AnyObject!
	@NSManaged var object : String!
	@NSManaged var tokenizationMethod : AnyObject!
	@NSManaged var rootClass : RootClass!
	@NSManaged var accountBalance : Int
	@NSManaged var created : Int
	@NSManaged var currency : AnyObject!
	@NSManaged var defaultSource : String!
	@NSManaged var delinquent : Bool
	@NSManaged var description : AnyObject!
	@NSManaged var discount : AnyObject!
	@NSManaged var email : String!
	@NSManaged var livemode : Bool
	@NSManaged var shipping : AnyObject!
	@NSManaged var sources : Source!
	@NSManaged var subscriptions : Subscription!


	/**
	 * Instantiate the instance using the passed dictionary values to set the properties values
	 */
	init(fromDictionary dictionary: NSDictionary, context: NSManagedObjectContext)	{
		let entity = NSEntityDescription.entityForName("Data", inManagedObjectContext: context)!
		super.init(entity: entity, insertIntoManagedObjectContext: context)
		if let sourceData = dictionary["source"] as? NSDictionary{
			source = Source(fromDictionary: sourceData, context:context)
		}
		if let addressCityValue = dictionary["address_city"] as? AnyObject{
			addressCity = addressCityValue
		}
		if let addressCountryValue = dictionary["address_country"] as? AnyObject{
			addressCountry = addressCountryValue
		}
		if let addressLine1Value = dictionary["address_line1"] as? AnyObject{
			addressLine1 = addressLine1Value
		}
		if let addressLine1CheckValue = dictionary["address_line1_check"] as? AnyObject{
			addressLine1Check = addressLine1CheckValue
		}
		if let addressLine2Value = dictionary["address_line2"] as? AnyObject{
			addressLine2 = addressLine2Value
		}
		if let addressStateValue = dictionary["address_state"] as? AnyObject{
			addressState = addressStateValue
		}
		if let addressZipValue = dictionary["address_zip"] as? AnyObject{
			addressZip = addressZipValue
		}
		if let addressZipCheckValue = dictionary["address_zip_check"] as? AnyObject{
			addressZipCheck = addressZipCheckValue
		}
		if let brandValue = dictionary["brand"] as? String{
			brand = brandValue
		}
		if let countryValue = dictionary["country"] as? String{
			country = countryValue
		}
		if let customerValue = dictionary["customer"] as? String{
			customer = customerValue
		}
		if let cvcCheckValue = dictionary["cvc_check"] as? String{
			cvcCheck = cvcCheckValue
		}
		if let dynamicLast4Value = dictionary["dynamic_last4"] as? AnyObject{
			dynamicLast4 = dynamicLast4Value
		}
		if let expMonthValue = dictionary["exp_month"] as? Int{
			expMonth = expMonthValue
		}
		if let expYearValue = dictionary["exp_year"] as? Int{
			expYear = expYearValue
		}
		if let fingerprintValue = dictionary["fingerprint"] as? String{
			fingerprint = fingerprintValue
		}
		if let fundingValue = dictionary["funding"] as? String{
			funding = fundingValue
		}
		if let idValue = dictionary["id"] as? String{
			id = idValue
		}
		if let last4Value = dictionary["last4"] as? String{
			last4 = last4Value
		}
		if let metadataData = dictionary["metadata"] as? NSDictionary{
			metadata = Metadata(fromDictionary: metadataData, context:context)
		}
		if let nameValue = dictionary["name"] as? AnyObject{
			name = nameValue
		}
		if let objectValue = dictionary["object"] as? String{
			object = objectValue
		}
		if let tokenizationMethodValue = dictionary["tokenization_method"] as? AnyObject{
			tokenizationMethod = tokenizationMethodValue
		}
		if let rootClassData = dictionary["rootClass"] as? NSDictionary{
			rootClass = RootClass(fromDictionary: rootClassData, context:context)
		}
		if let accountBalanceValue = dictionary["account_balance"] as? Int{
			accountBalance = accountBalanceValue
		}
		if let createdValue = dictionary["created"] as? Int{
			created = createdValue
		}
		if let currencyValue = dictionary["currency"] as? AnyObject{
			currency = currencyValue
		}
		if let defaultSourceValue = dictionary["default_source"] as? String{
			defaultSource = defaultSourceValue
		}
		if let delinquentValue = dictionary["delinquent"] as? Bool{
			delinquent = delinquentValue
		}
		if let descriptionValue = dictionary["description"] as? AnyObject{
			description = descriptionValue
		}
		if let discountValue = dictionary["discount"] as? AnyObject{
			discount = discountValue
		}
		if let emailValue = dictionary["email"] as? String{
			email = emailValue
		}
		if let livemodeValue = dictionary["livemode"] as? Bool{
			livemode = livemodeValue
		}
		if let shippingValue = dictionary["shipping"] as? AnyObject{
			shipping = shippingValue
		}
		if let sourcesData = dictionary["sources"] as? NSDictionary{
			sources = Source(fromDictionary: sourcesData, context:context)
		}
		if let subscriptionsData = dictionary["subscriptions"] as? NSDictionary{
			subscriptions = Subscription(fromDictionary: subscriptionsData, context:context)
		}
	}

	/**
	 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
	 */
	func toDictionary() -> NSDictionary {
		var dictionary = NSMutableDictionary()
		if source != nil{
			dictionary["source"] = source.toDictionary()
		}
		if addressCity != nil{
			dictionary["address_city"] = addressCity
		}
		if addressCountry != nil{
			dictionary["address_country"] = addressCountry
		}
		if addressLine1 != nil{
			dictionary["address_line1"] = addressLine1
		}
		if addressLine1Check != nil{
			dictionary["address_line1_check"] = addressLine1Check
		}
		if addressLine2 != nil{
			dictionary["address_line2"] = addressLine2
		}
		if addressState != nil{
			dictionary["address_state"] = addressState
		}
		if addressZip != nil{
			dictionary["address_zip"] = addressZip
		}
		if addressZipCheck != nil{
			dictionary["address_zip_check"] = addressZipCheck
		}
		if brand != nil{
			dictionary["brand"] = brand
		}
		if country != nil{
			dictionary["country"] = country
		}
		if customer != nil{
			dictionary["customer"] = customer
		}
		if cvcCheck != nil{
			dictionary["cvc_check"] = cvcCheck
		}
		if dynamicLast4 != nil{
			dictionary["dynamic_last4"] = dynamicLast4
		}
		if expMonth != nil{
			dictionary["exp_month"] = expMonth
		}		
		if expYear != nil{
			dictionary["exp_year"] = expYear
		}		
		if fingerprint != nil{
			dictionary["fingerprint"] = fingerprint
		}
		if funding != nil{
			dictionary["funding"] = funding
		}
		if id != nil{
			dictionary["id"] = id
		}
		if last4 != nil{
			dictionary["last4"] = last4
		}
		if metadata != nil{
			dictionary["metadata"] = metadata.toDictionary()
		}
		if name != nil{
			dictionary["name"] = name
		}
		if object != nil{
			dictionary["object"] = object
		}
		if tokenizationMethod != nil{
			dictionary["tokenization_method"] = tokenizationMethod
		}
		if rootClass != nil{
			dictionary["rootClass"] = rootClass.toDictionary()
		}
		dictionary["account_balance"] = accountBalance
		dictionary["created"] = created
		if currency != nil{
			dictionary["currency"] = currency
		}
		if defaultSource != nil{
			dictionary["default_source"] = defaultSource
		}
		dictionary["delinquent"] = delinquent
		if description != nil{
			dictionary["description"] = description
		}
		if discount != nil{
			dictionary["discount"] = discount
		}
		if email != nil{
			dictionary["email"] = email
		}
		dictionary["livemode"] = livemode
		if shipping != nil{
			dictionary["shipping"] = shipping
		}
		if sources != nil{
			dictionary["sources"] = sources.toDictionary()
		}
		if subscriptions != nil{
			dictionary["subscriptions"] = subscriptions.toDictionary()
		}
		return dictionary
	}

}
//
//	RootClass.swift
//	Model file Generated using JSON Modeler: http://www.jbsolutions.net/json-modeler

import Foundation
import CoreData

class RootClass : NSManagedObject {

	@NSManaged var data : NSMutableSet!
	@NSManaged var hasMore : Bool
	@NSManaged var object : String!
	@NSManaged var url : String!


	/**
	 * Instantiate the instance using the passed dictionary values to set the properties values
	 */
	init(fromDictionary dictionary: NSDictionary, context: NSManagedObjectContext)	{
		let entity = NSEntityDescription.entityForName("RootClass", inManagedObjectContext: context)!
		super.init(entity: entity, insertIntoManagedObjectContext: context)
		if let dataArray = dictionary["data"] as? [NSDictionary]{
			var dataSet = NSMutableSet()
			for dic in dataArray{
				let value = Data(fromDictionary: dic, context:context)
				dataSet.addObject(value)
			}
			data = dataSet
		}
		if let hasMoreValue = dictionary["has_more"] as? Bool{
			hasMore = hasMoreValue
		}
		if let objectValue = dictionary["object"] as? String{
			object = objectValue
		}
		if let urlValue = dictionary["url"] as? String{
			url = urlValue
		}
	}

	/**
	 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
	 */
	func toDictionary() -> NSDictionary
	{
		var dictionary = NSMutableDictionary()
		if data != nil{
			var dictionaryElements = [NSDictionary]()
			for dataElement in data {
				dictionaryElements.append(dataElement.toDictionary())
			}
			dictionary["data"] = dictionaryElements
		}
		dictionary["has_more"] = hasMore
		if object != nil{
			dictionary["object"] = object
		}
		if url != nil{
			dictionary["url"] = url
		}
		return dictionary
	}

}
//
//	Source.swift
//	Model file Generated using JSON Modeler: http://www.jbsolutions.net/json-modeler

import Foundation
import CoreData

class Source : NSManagedObject {

	@NSManaged var data : Data!
	@NSManaged var data : NSMutableSet!
	@NSManaged var hasMore : Bool
	@NSManaged var object : String!
	@NSManaged var totalCount : Int
	@NSManaged var url : String!


	/**
	 * Instantiate the instance using the passed dictionary values to set the properties values
	 */
	init(fromDictionary dictionary: NSDictionary, context: NSManagedObjectContext)	{
		let entity = NSEntityDescription.entityForName("Source", inManagedObjectContext: context)!
		super.init(entity: entity, insertIntoManagedObjectContext: context)
		if let dataData = dictionary["data"] as? NSDictionary{
			data = Data(fromDictionary: dataData, context:context)
		}
		if let dataArray = dictionary["data"] as? [NSDictionary]{
			var dataSet = NSMutableSet()
			for dic in dataArray{
				let value = Data(fromDictionary: dic, context:context)
				dataSet.addObject(value)
			}
			data = dataSet
		}
		if let hasMoreValue = dictionary["has_more"] as? Bool{
			hasMore = hasMoreValue
		}
		if let objectValue = dictionary["object"] as? String{
			object = objectValue
		}
		if let totalCountValue = dictionary["total_count"] as? Int{
			totalCount = totalCountValue
		}
		if let urlValue = dictionary["url"] as? String{
			url = urlValue
		}
	}

	/**
	 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
	 */
	func toDictionary() -> NSDictionary {
		var dictionary = NSMutableDictionary()
		if data != nil{
			var dictionaryElements = [NSDictionary]()
			for dataElement in data {
				dictionaryElements.append(dataElement.toDictionary())
			}
			dictionary["data"] = dictionaryElements
		}
		if hasMore != nil{
			dictionary["has_more"] = hasMore
		}
		if object != nil{
			dictionary["object"] = object
		}
		if url != nil{
      	  		dictionary["url"] = url
		}
		if url != nil{
			dictionary["url"] = url
		}
		return dictionary
	}

}
//
//	Subscription.swift
//	Model file Generated using JSON Modeler: http://www.jbsolutions.net/json-modeler

import Foundation
import CoreData

class Subscription : NSManagedObject {

	@NSManaged var data : Data!
	@NSManaged var data : NSMutableSet!
	@NSManaged var hasMore : Bool
	@NSManaged var object : String!
	@NSManaged var totalCount : Int
	@NSManaged var url : String!


	/**
	 * Instantiate the instance using the passed dictionary values to set the properties values
	 */
	init(fromDictionary dictionary: NSDictionary, context: NSManagedObjectContext)	{
		let entity = NSEntityDescription.entityForName("Subscription", inManagedObjectContext: context)!
		super.init(entity: entity, insertIntoManagedObjectContext: context)
		if let dataData = dictionary["data"] as? NSDictionary{
			data = Data(fromDictionary: dataData, context:context)
		}
		if let dataArray = dictionary["data"] as? [NSDictionary]{
			var dataSet = NSMutableSet()
			for dic in dataArray{
				let value = AnyObject(fromDictionary: dic, context:context)
				dataSet.addObject(value)
			}
			data = dataSet
		}
		if let hasMoreValue = dictionary["has_more"] as? Bool{
			hasMore = hasMoreValue
		}
		if let objectValue = dictionary["object"] as? String{
			object = objectValue
		}
		if let totalCountValue = dictionary["total_count"] as? Int{
			totalCount = totalCountValue
		}
		if let urlValue = dictionary["url"] as? String{
			url = urlValue
		}
	}

	/**
	 * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property
	 */
	func toDictionary() -> NSDictionary {
		var dictionary = NSMutableDictionary()
		if data != nil{
			var dictionaryElements = [NSDictionary]()
			for dataElement in data {
				dictionaryElements.append(dataElement.toDictionary())
			}
			dictionary["data"] = dictionaryElements
		}
		if hasMore != nil{
			dictionary["has_more"] = hasMore
		}
		if object != nil{
			dictionary["object"] = object
		}
		dictionary["total_count"] = totalCount
		if url != nil{
			dictionary["url"] = url
		}
		return dictionary
	}

}
Web Analytics