Hi Guys
Just trying to save data to a JSON column and following this example in the swift docs:
let profile = ["name": "Joe",
"age": 34,
"address": ["street": "123 Main St",
"city" : "New York",
"state": "New York"],
"favoriteNumbers": [5, 7, 9, 21, 100],
"favoriteColors": ["Blue", "Green"]
] as [String : Any]
Backendless.shared.data.ofTable("Person").save(entity: ["profile": profile], responseHandler: { response in
print(response)
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
When I save this, the information within the arrays is not saved, the other info like age and name is present and correct. Any ideas?
{
“age”: 34,
“name”: “Joe”,
“address”: {
“city”: “New York”,
“state”: “New York”,
“street”: “123 Main St”
},
“favoriteColors”: {},
“favoriteNumbers”: {}
}
Hello @mike-turner,
Does this issue still occur? If so, could you please provide App Id where this problem is reproduced?
I’ve just checked the same code and everything was created successfully in my App.
Regards,
Olha
Hi @olhadanylova
APP ID: 2E8ADF1B-C249-E5A2-FF7F-971967CDE100
Yes, still occuring. You might actually recognise the code as I am just trying to extend the Swift Chat app you created.
I am actually trying to save to a custom class, MessageObject as defined below. The delivered column is the JSON column in question.
You can do a test save to the delivered column in MessageObject table, only test data there at the moment.
@objcMembers class MessageObject: NSObject {
var objectId: String?
var userId: String?
var userName: String?
var messageText: String?
var imagePath: String?
var created: Date?
var updated: Date?
var channel: String?
var delivered: [String : Any]?
}
and the save component part is
let profile = ["name": "Joe",
"age": 34,
"address": ["street": "123 Main St",
"city" : "New York",
"state": "New York"],
"favoriteNumbers": [5, 7, 9, 21, 100],
"favoriteColors": ["Blue", "Green"]
] as [String : Any]
//Json test - using 'profile' data from the docs
message.delivered = profile
self.messageStore.save(entity: message, responseHandler: { updatedMessageObject in
print("read receipt saved")
}, errorHandler: { fault in
print("read receipt could not be saved!")
}
})
I was able to reproduce this issue. The internal ticket BKNDLSS-29425 is created for fix.
Regards,
Olha
OK, thanks.
Is there a work around you know of to save an array in a JSON column in the meantime?
Mike
Issue occurs when using custom objects. It should work fine if saving object as Dictionary, e.g.
let profile = ["name": "Joe",
"age": 34,
"address": ["street": "123 Main St",
"city" : "New York",
"state": "New York"],
"favoriteNumbers": [5, 7, 9, 21, 100],
"favoriteColors": ["Blue", "Green"]
] as [String : Any]
let person = ["objectId": "CE3F4C1F-7C0A-40D5-B4A7-D3A878CBEE79", "profile": profile] as [String : Any]
Backendless.shared.data.ofTable("Person").save(entity: person, responseHandler: { savedPerson in
print(savedPerson)
}, errorHandler: { fault in
print("Error: \(fault.message ?? "")")
})
The fix is about to be released today or tomorrow.
Ahh, ok
Thanks very much for clarifying and for the quick fix.
Mike
1 Like
Could you please check with Swift-SDK v6.6.1?
Hi @olhadanylova, confirm Swift-SDK v6.6.1 is saving JSON correctly now using custom object approach. Many thanks, Mike
1 Like