1

According to AutoValue documentation annotating the abstract class with @GwtCompatible(serializable = true) and implementing serializable should be enough for the generated value class to be usable in GWT RPCs. Yet, with the class below I am getting the following error:

Caused by: com.google.gwt.user.client.rpc.SerializationException: 
Type 'com.my.package.client.types.AutoValue_PersonLocalData' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. 
For security purposes, this type will not be serialized.: instance = PersonLocalData{title=Dr., givenName=Philip, familyName=Mortimer}

I tried various variant (like only implementing the regular Serializable) without success. What is wrong with the class?

import java.io.Serializable;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.GwtCompatible;
import com.google.gwt.user.client.rpc.IsSerializable;

@AutoValue
@GwtCompatible(serializable = true)
public abstract class PersonLocalData
        implements IsSerializable, Serializable {

    public static final long serialVersionUID = 1L;

    public static PersonLocalData create(
            String title,
            String givenName,
            String familyName) {
        return new AutoValue_PersonLocalData(
                title, givenName, familyName);
    }

    public abstract String getTitle();
    public abstract String getGivenName();
    public abstract String getFamilyName();
}

Gradle file includes

compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava-gwt:18.0'
compile 'com.google.auto.value:auto-value:1.1'

GWT version: 2.6.0

Pierre-Antoine
  • 7,939
  • 6
  • 28
  • 36
  • Did you include the generated sources (source for `AutoValue_PersonLocalData`) into the classpath for the GWT compiler? Maybe you could show more of your `build.gradle`. – Thomas Broyer Jul 04 '15 at 14:14
  • I am using the GWT plugin for gradle available here: https://steffenschaefer.github.io/gwt-gradle-plugin/doc/latest/configuration with the jetty and war plugin. However, I doubt that the generated source is not accessible from GWT otherwise the stacktrace could not have called the toString on the object after "instance =". – Pierre-Antoine Jul 05 '15 at 16:40
  • 2
    IIUC, this message is shown on the server, and says the serialization policy (generated by GWT) doesn't include the class, so it could be that GWT didn't see/have the class but the server does. – Thomas Broyer Jul 05 '15 at 22:09
  • I created several types, and it seems that the problem comes from autovalue type that have nested autovalue types. – Pierre-Antoine Jul 16 '15 at 20:42
  • Well, it's supposed to work: https://github.com/google/auto/pull/257 – Thomas Broyer Jul 17 '15 at 16:18

1 Answers1

0

GWT and annotation processing are uncomfortable bedfellows. The key seems to be to separate annotation processing out into a prerequisite step. For example, I just got this working with Maven by following the Groups topic BoilerplateGeneration maven configuration: disable annotation processing in the compilation step, and instead run it as part of generate-sources, so GWT can treat them as source files when it runs. In the past, I've compiled my annotated classes into a JAR (including the generated source code) and run GWT compilation on a separate project which includes that JAR. Unfortunately, I don't have Gradle-specific advice.

Alice Purcell
  • 12,622
  • 6
  • 51
  • 57