thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

Can't save current user as object in User Pointer column (Parse4J) #85

Open SeloSlav opened 7 years ago

SeloSlav commented 7 years ago

Anybody else have a similar problem?

ParseUser currentUser = ParseUser.currentUser;

ParseObject sentRequest = new ParseObject("Request");
sentRequest.put("author", currentUser);
try {
 sentRequest.save();
} catch (org.parse4j.ParseException e) {
 e.printStackTrace();
}

pom.xml: I'm using the latest SNAPSHOT build as my Parse4J dependency.

    <dependency>
        <groupId>com.github.thiagolocatelli</groupId>
        <artifactId>parse4j</artifactId>
        <version>1.5-SNAPSHOT</version>
    </dependency>

Exception:

ParseException [code=111, error=schema mismatch for Request.author; expected Pointer<_User> but got Pointer<users>]
    at org.parse4j.command.ParseResponse.getParseError(ParseResponse.java:122)
    at org.parse4j.command.ParseResponse.getException(ParseResponse.java:78)
    at org.parse4j.ParseObject.save(ParseObject.java:486)
    at com.test.automation.controller.RequestController.createRequestObject(RequestController.java:119)
    at com.test.automation.controller.RequestController.saveRequest(RequestController.java:89)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

What's going wrong here?

SeloSlav commented 7 years ago

It works when you query for the current user, but I think that's kind of unnecessary. I'd love to know why my first attempt fails....

ParseQuery<ParseObject> userQuery = ParseQuery.getQuery("_User");
        userQuery.whereEqualTo("objectId", currentUser.getObjectId());
        try {
            List<ParseObject> userList = userQuery.find();
            for (ParseObject author : userList) {

                sentRequest.put("author", author);
                try {
                    sentRequest.save();
                } catch (org.parse4j.ParseException e) {
                    e.printStackTrace();
                }

            }
        } catch (org.parse4j.ParseException e) {
            e.printStackTrace();
        }