ParseObject.fromJson is not working properly
New Issue Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest version of Parse Server and the Parse Flutter SDK.
Issue Description
ParseObject.fromJson function is not sending the proper payload to the server. This is the exact same bug with #568 and #630.
Steps to reproduce
var map = {
'firstName': 'Barbie',
'lastName': 'Lee',
};
ParseObject obj = ParseObject('Models').fromJson(map);
ParseResponse res = await obj.save();
Actual Outcome
As you can see the -d flag does not contain anything:
I/flutter ( 4119): ╭-- Parse Request
I/flutter ( 4119): curl -X POST -H 'content-type: text/plain; charset=utf-8' -H 'user-agent: Flutter Parse SDK 3.1.0' -H 'X-Parse-Application-Id: [redacted]' -H 'X-Parse-Session-Token: [redacted]' -H 'X-Parse-Client-Key: [redacted]' -d '{}' https://parseapi.back4app.com/classes/Models
I/flutter ( 4119):
I/flutter ( 4119): https://parseapi.back4app.com/classes/Models
I/flutter ( 4119): ╰--
Expected Outcome
Using a forEach loop to set the object value, I can achieve the following:
I/flutter ( 4119): ╭-- Parse Request
I/flutter ( 4119): curl -X POST -H 'content-type: text/plain; charset=utf-8' -H 'user-agent: Flutter Parse SDK 3.1.0' -H 'X-Parse-Application-Id: [redacted]' -H 'X-Parse-Session-Token: [redacted]' -H 'X-Parse-Client-Key: [redacted]' -d '{"firstName":"Barbie","lastName":"Lee"}' https://parseapi.back4app.com/classes/Models
I/flutter ( 4119):
I/flutter ( 4119): https://parseapi.back4app.com/classes/Models
I/flutter ( 4119): ╰--
Environment
Flutter 2.5.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 3595343e20 (5 weeks ago) • 2021-09-30 12:58:18 -0700
Engine • revision 6ac856380f
Tools • Dart 2.14.3
Parse Flutter SDK
- SDK version: 3.1.0
- Operating system version: macOS
Server
- Parse Server version: back4app
Thanks for opening this issue!
- 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.
It seems that the problem is solved. I tested it and there was no problem
I'll go ahead and close this since the issue was not reproducible @hinryd please try again with the latest package version and we can reopen this issue if you still face it.
I am also seeing a similar issue. My test code is:
var firstObject = ParseObject('TestTrip')
..fromJson({'description': 'A test Trip 2'});
print(firstObject);
var secondObject = ParseObject('TestTrip')
..set('description', 'A test trip 3');
print(secondObject);
await secondObject.save();
await firstObject.save();
the resulting output (from print) is
flutter: {"className":"TestTrip","description":"A test Trip 2"}
flutter: {"className":"TestTrip","description":"A test trip 3"}
It creates both records but the one created using fromJson has no data fields (i.e. the description is missing).
- Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-x64, locale en-GB)
- parse_server_sdk_flutter: ^3.1.3
is there a step I am missing if I want to use fromJson ?
I am also seeing a similar issue. My test code is:
var firstObject = ParseObject('TestTrip') ..fromJson({'description': 'A test Trip 2'}); print(firstObject); var secondObject = ParseObject('TestTrip') ..set('description', 'A test trip 3'); print(secondObject); await secondObject.save(); await firstObject.save();the resulting output (from print) is
flutter: {"className":"TestTrip","description":"A test Trip 2"} flutter: {"className":"TestTrip","description":"A test trip 3"}It creates both records but the one created using fromJson has no data fields (i.e. the description is missing).
- Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-x64, locale en-GB)
- parse_server_sdk_flutter: ^3.1.3
is there a step I am missing if I want to use fromJson ?
Did you register TestTrip?
@mbfakourii not sure what you mean, but I guess then the answer is no.
I assume that fromJson does not do what I think it does - I assumed that it would populate (in my case) the TestTrip object with the data in the supplied json.
I am using Back4App and the save() pushes both records to the backend, it's just that there is no data added to the record when using fromJson , but objectId, createdAt, updatedAt and ACL are generated.
Below is the code
await Parse().initialize(keyApplicationId, keyParseServerUrl,
clientKey: keyClientKey, autoSendSessionId: true);
var firstObject = ParseObject('TestTrip')
..fromJson({'description': 'A test Trip 2'});
print(firstObject);
var secondObject = ParseObject('TestTrip')
..set('description', 'A test trip 3');
print(secondObject);
await secondObject.save();
await firstObject.save();
debugPrint('done');
@magnatronus Thank you for reporting this issues, I will try to solve it in a PR