Skip to content
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

ParseUser not supporting custom property ParseGeoPoint #142

Closed
danibjor opened this issue Mar 29, 2019 · 12 comments
Closed

ParseUser not supporting custom property ParseGeoPoint #142

danibjor opened this issue Mar 29, 2019 · 12 comments

Comments

@danibjor
Copy link

danibjor commented Mar 29, 2019

Sample code:

var user = await ParseUser.currentUser(); 
if (user != null) {
    var location = ParseGeoPoint(latitude: 48.858372, longitude: 2.294481);
    user.set<ParseGeoPoint>('location', location);
    var response = await user.save();
}

.save() throws exception:

Exception has occurred.
JsonUnsupportedObjectError (Converting object to an encodable object failed: Instance of 'ParseGeoPoint')

Edit: as of v1.0.16

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Mar 29, 2019

Very strange. for me it's working.

dependencies:
  flutter:
    sdk: flutter
  parse_server_sdk: ^1.0.16

My code:

  var parseObject = ParseObject("TestAPI", debug: true);
  parseObject.set<String>("stringName", "Name");
  parseObject.set<double>("doubleNumber", 1.5);
  parseObject.set<int>("intNumber", 0);
  parseObject.set<bool>("boolFound", true);
  parseObject.set<List<String>>("listString", ["a", "b", "c", "d"]);
  parseObject.set<List<int>>("listNumber", [0, 1]);
  parseObject.set<DateTime>("dateTest", DateTime.now());
  parseObject.set<Map<String, dynamic>>(
      "jsonTest", {"field1": "value1", "field2": "value2"});
  parseObject.setIncrement("intNumber2", 2);
  parseObject.setDecrement("intNumber3", 2);
  //parseObject.set<ParseGeoPoint>(
  //    "location", ParseGeoPoint(latitude: -20.2523818, longitude: -40.2665611));

  final location = ParseGeoPoint(latitude: 48.858372, longitude: 2.294481);
  parseObject.set<ParseGeoPoint>("location", location);

  parseObject.set<ParseUser>("user", user);
  parseObject.set<ParseObject>(
      "produto", ParseObject("Produto")..set("objectId", "E7o3gkZD2T"));
  parseObject.set<List<ParseUser>>("users", [user, user]);
  parseObject.set<ParseFile>("fileImage", parseFile);
  parseObject.set<List<ParseFile>>("fileImages", [parseFile, parseFile]);

  apiResponse = await parseObject.save();

Response:

Payload: {"className":"TestAPI","objectId":"A6SEZ7rVIt","createdAt":"2019-03-29T18:05:02.398Z","stringName":"Name","doubleNumber":1.5,"intNumber":0,"boolFound":true,"listString":["a","b","c","d"],"listNumber":[0,1],"dateTest":{"__type":"Date","iso":"2019-03-29T18:05:01.768Z"},"jsonTest":{"field1":"value1","field2":"value2"},"intNumber2":2,"intNumber3":-2,"location":{"__type":"GeoPoint","latitude":48.858372,"longitude":2.294481},"user":{"__type":"Pointer","className":"_User","objectId":"0C6ptX39c8"},"produto":{"__type":"Pointer","className":"Produto","objectId":"E7o3gkZD2T"},"users":[{"__type":"Pointer","className":"_User","objectId":"0C6ptX39c8"},{"__type":"Pointer","className":"_User","objectId":"0C6ptX39c8"}],"fileImage":{"__type":"File","name":"08dacb56744a958932de46583369b44d_image.png","url":"https://api.feitoemcasaapp.com/1/files/HIn4bvCmAYvwpDmPTmRjfoSwpTPPmGsPUMKYU36Q/08dacb56744a958932de46583369b44d_image.png<…>

@danibjor
Copy link
Author

Sure, but you don’t add GeoPoint to a User object in your test case. 😉

Works fine on ParseInstallation class, and on “regular” ParseObject (and subclassed) here too.

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Mar 29, 2019

@danibjor
OK. then the problem only occurs with class _User?

I did the test here and also the error occurred for me.

@RodrigoSMarques
Copy link
Contributor

@danibjor
I found the problem, I'm going to do a PR.

@phillwiggins
Should I use which branch?

@phillwiggins
Copy link
Member

phillwiggins commented Mar 29, 2019 via email

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Apr 1, 2019

@phillwiggins
I did not have time to change the code and submit a PR.

The problem is in the save method on the line containing json.encode.

Just remove toEncodable.

Parse data types are already being handled in toJson and calling toEncodable causes error.

Future<ParseResponse> save() async {
...
final Uri url = getSanitisedUri(_client, '$_path/$objectId');
        final String body =
            json.encode(toJson(forApiRQ: true), toEncodable: dateTimeEncoder);
...

Change to:

Future<ParseResponse> save() async {
...
final Uri url = getSanitisedUri(_client, '$_path/$objectId');
        final String body =
            json.encode(toJson(forApiRQ: true));
..

@phillwiggins
Copy link
Member

@RodrigoSMarques
Good spotting. Due to ParseUser extending ParseObject, we should be fine just to use super.save(). Thank you

@danibjor
This looks to be working on branch release/1.0.17. If you have a chance and want to test this as well you can, or if you want, you can wait until the next release is created. Please let me know if you have a chance and this fixes your issue.

@danibjor
Copy link
Author

danibjor commented Apr 1, 2019

@phillwiggins just tested, but my app breaks on ParseInstallation if I'm switching to 1.0.17.

parse_installation.dart line 129

128: if (installationMap != null) {
129:        return ParseInstallation()..fromJson(installationMap);
Exception has occurred.
_TypeError (type 'ParseObject' is not a subtype of type 'Map<String, dynamic>')

@danibjor
Copy link
Author

danibjor commented Apr 1, 2019

@phillwiggins tried changing the sources manually (adding the fix pointed out) and commenting out stuff related to ParseInstallation.

Still no go - it saves, but the data is not showing up on the server.

Been digging and it seems like the data is not persisted on the GeoPoint object. I make a new GeoPoint, set it on the user and save().

ParseGeoPoint seems to be broken on 1.0.17

image

Created a pull request that fixes the ParseGeoPoint. Data (location prop of type GeoPoint) on the User object is now persisted on the server. #143

@RodrigoSMarques
Copy link
Contributor

Strange that I had already hit Geopoint in branch v1.0.16.

I tested the branch 1.0.17 and ParseFile is in error.

The strange thing is that the Master code is OK and works correctly in branch v1.0.16 (last).

I think it gave some trouble in the merge.

[VERBOSE-2: ui_dart_state.cc (148)] Unhandled Exception: Stack Overflow
# 0 ParseFile.toString
../.../Objects/parse_file.dart:44
# 1 ParseFile.toString
../.../Objects/parse_file.dart:45
# 2 ParseFile.toString
../.../Objects/parse_file.dart:45
# 3 ParseFile.toString
../.../Objects/parse_file.dart:45
# 4 ParseFile.toString
../.../Objects/parse_file.dart:45
# 5 Pair <...>

@phillwiggins
Copy link
Member

There's not been much movement on this recently. Are we safe to close?

@kaustubhspn
Copy link

kaustubhspn commented Sep 5, 2019

There's not been much movement on this recently. Are we safe to close?

Yes, the GeoPoint is working perfectly well, even with the _User class now!
So I believe this can be closed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants