1
votes

Google states that the the Google App Engine Datastore support the following types.

Java Properties and value types

Among these is com.google.appengine.api.users.User.

However when I try to persist my entity it is throwing the following excpetion.

[INFO] java.lang.NullPointerException
[INFO]  at com.google.storage.onestore.v3.OnestoreEntity$PropertyValue$UserValue.setAuthDomain(OnestoreEntity.java:1145)
[INFO]  at com.google.appengine.api.datastore.DataTypeTranslator$UserType.toV3Value(DataTypeTranslator.java:994)
[INFO]  at com.google.appengine.api.datastore.DataTypeTranslator.addPropertyToPb(DataTypeTranslator.java:165)
[INFO]  at com.google.appengine.api.datastore.DataTypeTranslator.addPropertiesToPb(DataTypeTranslator.java:138)
[INFO]  at com.google.appengine.api.datastore.EntityTranslator.convertToPb(EntityTranslator.java:61)
[INFO]  at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$4.toPb(AsyncDatastoreServiceImpl.java:203)
[INFO]  at com.google.appengine.api.datastore.AsyncDatastoreServiceImpl$4.toPb(AsyncDatastoreServiceImpl.java:180)
[INFO]  at com.google.appengine.api.datastore.Batcher$BatchIterator.<init>(Batcher.java:177)
...

I tried registering it with Objectify using my own service, but it'll just say entity not found, not surprising as it is not annotated with Objectify's @Entity.

How do you persist the Google User type with Objectify?

** UPDATE **

I seem to be having problems with other Google Types as well.

e.g. com.google.appengine.api.datastore.Email

Entity Class

package com.propertywrassler.webservice.maintenance;

import com.google.api.server.spi.response.BadRequestException;
import com.google.appengine.api.users.User;
import com.googlecode.objectify.annotation.Entity;
import com.propertywrassler.webservice.util.ErrorMessage;
import com.propertywrassler.webservice.util.PropertyWrasslerChildEntity;
import lombok.Getter;
import lombok.Setter;
import org.joda.time.DateTime;

@Entity
public class Comment extends MyChildEntity<ThingYouComment, Comment> {

    @Getter @Setter private User author;
    @Getter @Setter private DateTime timeStamp = new DateTime();
    @Getter @Setter private String text;

    @Override
    public void validate() throws BadRequestException {
        super.validate();
        if (author == null) {
            throw new BadRequestException(ErrorMessage.requiredField("author"));
        }
        if (text == null) {
            throw new BadRequestException(ErrorMessage.requiredField("text"));
        }
    }

}

In Service I persist like so. Everything works fine till service. Endpoints serialized the object correctly and all. User object is perfect. Problem is at the following line.

ofy().save().entity(comment).now();
1
May go better if you paste the code you're using. - Albert
@BeroDotnet Pasted all that's relevant. Let me know if there is more you need. But this is looking like an Objectify issue. - Marc M.
It has nothing to do with Objectify; you can see from the stack trace that Objectify is passing the User object as-is into the GAE low-level API, and that the low-level API recognizes it as a User object. It looks like the value for User.authDomain is null. - stickfigure

1 Answers

0
votes

I tried using the User object that the Cloud Endpoint resource methods passes as the value for author everything worked.

It seems that passing a JSON User object from the JS client is not the same as the User object from the server instance. They don't have the same fields and even the shared fields have different names. e.g. on the JS client a Googe User type calls the user ID id, but on the Java back end it's called userId.