Shopify / mobile-buy-sdk-ios

Shopify’s Mobile Buy SDK makes it simple to sell physical products inside your mobile app. With a few lines of code, you can connect your app with the Shopify platform and let your users buy your products using Apple Pay or their credit card.
MIT License
452 stars 199 forks source link

Invalid type in JSON write #968

Closed ksatasiya closed 5 years ago

ksatasiya commented 5 years ago

Getting error when storefront.AttributeInput when I am trying to prase JSONSerialization.

This is error: 'Invalid type in JSON write (_TtCC12MobileBuySDK10Storefront14AttributeInput)'

//This Method private func flush() { let serializedItems = self.items.serialize()

    self.ioQueue.async {
        do {

            let data = try! JSONSerialization.data(withJSONObject: serializedItems, options: [])

            try data.write(to: self.cartURL, options: [.atomic])

            print("Flushed cart to disk.")

        } catch let error {
            print("Failed to flush cart to disk: \(error)")
        }

        DispatchQueue.main.async {
            self.needsFlush = false
        }
    }
}

Show properties

"quantity": 1, "properties": [MobileBuySDK.Storefront.AttributeInput, MobileBuySDK.Storefront.AttributeInput, MobileBuySDK.Storefront.AttributeInput, MobileBuySDK.Storefront.AttributeInput], "variant": ["cursor": eyJsYXN0X2lkIjoxNTQ0ODY3NDY2NDUyMCwibGFzdF92YWx1ZSI6MX0=, "node": { availableForSale = 1; compareAtPrice = "98.81"; id = "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8xNTQ0ODY3NDY2NDUyMA=="; price = "54.99"; selectedOptions = ( { name = Title; value = "Default Title"; } ); sku = SQ4829653; title = "Default Title"; }]

dbart01 commented 5 years ago

You're likely encountering a versioning mismatch between your serialized models on disk and the new version coming from GraphQL. Please take a look at this potential duplicate issue for some suggestions on how to deal with this in the future.

I just want to be clear that this is an issue with your application, not the SDK. The sample app that ships alongside the SDK is provided as a sample, only.