-
-
Notifications
You must be signed in to change notification settings - Fork 69
Decoding error when saving nested object #157
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi Pau, your nested object properties need to be "optional" because after it's saved it will come back as a Parse Pointer and will not contain the property struct language : ParseObject{
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var code : String? //change to optional
} Because of this, I recommend making all of your properties optional as you most likely have pointers to many of your Parse Objects in the future. You can look at the playgrounds for examples: https://github.com/parse-community/Parse-Swift/blob/main/ParseSwift.playground/Pages/8%20-%20Pointers.xcplaygroundpage/Contents.swift |
Also, be sure to check through closed issues. This has been answered before here: #130 (comment) |
Thanks for your prompt reply Corey! I am afraid changing the property to optional is not solving the issue. I've tried once again with the example code in the playgrounds you linked and I am getting the same exact error: Fatal error: Error saving: ParseError(code: ParseSwift.ParseError.Code.unknownError, message: "decoding error: typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))") |
What version of the Swift SDK and the parse-server are you running? I just ran the latest version of the Swift SDK against the latest server and 4.5.0 and I'm not getting any errors. Also, the test cases in the SDK will catch this if it is broken |
I installed the SDK via Podfile this morning
And it looks like I am running 3.9. I'll upgrade to 4.5 and try this again "parse-server": "^3.9.0" EDIT: BTW, despite being able to save a language option, I am getting these:
|
Maybe you saved your Parse class properties with different types than your current type. If you use Parse Dashboard to delete your old class (assuming you only have dummy data in there) and then save your current type, it might fix your issue. The types for your properties need to match the types on your Parse server database (mongo or postgres) The log output you sent seems related to your Xcode and network connection and don't seem to be related to the Swift SDK |
I am using MongoDB and this is just a test project so everything is dummy data. This might sound stupid, but do I need to create each class in the database before trying to save instances there? I have not done so for language |
Not necessarily, as long as you didn't set You can see all of the server configuration options here: http://parseplatform.org/parse-server/api/master/ParseServerOptions.html |
Tried also deleting any previously saved data in the database but it's not that either. I guess I'll start from scratch tomorrow with a fresh install. Thanks for your help! |
Re-installed everything. Created a new Xcode project (with the playgrounds examples, book and author) and I am encountering the same exact behavior.
Any other ideas why this might be happening? |
This is a bug as it looks like the parse-server has issues supporting transactions for mongo (doesn't occur with postgres). I'm working on a PR that will turn off transactions by default for internal operations in the Swift SDK such as saving child objects/pointers. The SDK began using transactions by default in Swift SDK 1.2.1, so I suspect 1.2.0 below work well with mongo |
@ribotinho thanks reporting and retesting. Can you let us know if v1.8.1 solves the problem? When using the playgrounds, be sure to "Clean Build Folder" via Xcode |
@cbaker6 I confirm the issue is now fixed and I can successfully save the nested object. Thanks a ton once again for your help! :) |
Thanks for reporting! Let us know if you find any other bugs or suggested improvements. |
Hi all,
I am encountering an issue when saving a nested object.
I have a teacher object that has a name (string) and a language (custom object)
I have no problem creating and saving language objects, but when I try to save a Teacher object I am getting a decoding error:
ParseError(code: ParseSwift.ParseError.Code.unknownError, message: "decoding error: typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))")
I am running the parse server on a localhost. macOS Big Sur and SwiftUI.
I have also tried saving the example of Author and Book in the Swift Playgrounds example code but I am getting exactly the same output.
Any one would know how can I solve this? Or what I am missing?
Kind regards,
Pau
The text was updated successfully, but these errors were encountered: