gwt-jackson icon indicating copy to clipboard operation
gwt-jackson copied to clipboard

Issues with incremental SDM compilation in GWT 2.8.0 beta1

Open christianbauer opened this issue 8 years ago • 7 comments

Trying to enable field-only serialization on this class (note the "illegal" isBar() getter name, JavaBean says it should be getBar() for a bean property, so must use field access):

public class Foo {

    protected Boolean bar;

    public Boolean isBar() {
        return bar;
    }

    public void setBar(Boolean bar) {
        this.bar = bar;
    }
}

This is the mixin:

@JsonAutoDetect(
    getterVisibility = JsonAutoDetect.Visibility.NONE,
    creatorVisibility = JsonAutoDetect.Visibility.NONE,
    fieldVisibility = JsonAutoDetect.Visibility.ANY,
    isGetterVisibility = JsonAutoDetect.Visibility.NONE)
public abstract class FooMapperMixin {
}

And the mapper:

@JsonMixIns({@JsonMixIns.JsonMixIn(target = Foo.class, mixIn = FooMapperMixin.class)})
public interface FooMapper extends ObjectMapper<Foo> {
}

Error:

java.lang.IllegalArgumentException: object is not an instance of declaring class
        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:497)
        at com.google.gwt.dev.javac.AnnotationProxyFactory$AnnotationProxyInvocationHandler.invoke(AnnotationProxyFactory.java:248)
        at com.sun.proxy.$Proxy124.mixIn(Unknown Source)
        at com.github.nmorel.gwtjackson.rebind.RebindConfiguration.addMixInAnnotations(RebindConfiguration.java:493)
        at com.github.nmorel.gwtjackson.rebind.RebindConfiguration.<init>(RebindConfiguration.java:220)
        at com.github.nmorel.gwtjackson.rebind.ObjectMapperGenerator.generate(ObjectMapperGenerator.java:34)

Workaround, extend AbstractConfiguration:

        addMixInAnnotations( Foo.class, FooMapperMixin.class );

christianbauer avatar May 25 '16 09:05 christianbauer

Actually, none of this works for me. The mixin is not applied.

christianbauer avatar May 25 '16 09:05 christianbauer

This should fail the build with an error instead of a warning message:

                try {
                    builder.add( (AbstractConfiguration) Class.forName( value ).newInstance() );
                } catch ( Exception e ) {
                    logger.log( Type.WARN, "Cannot instantiate the configuration class " + value );
                }

christianbauer avatar May 25 '16 10:05 christianbauer

The problems I'm seeing are most likely all related to incremental compilation in SDM. Unfortunately this is the default in GWT 2.8.0 and disabling it directly is not supported by the Gradle GWT plugin. Workaround:

tasks.withType(de.richsource.gradle.plugins.gwt.AbstractGwtActionTask) {
    args "-noincremental"
}

christianbauer avatar May 25 '16 10:05 christianbauer

First time I try the SDM in 2.8.0. I didn't reproduce the exception but had issues to get the incremental compiler see my changes.

I added a new MyMixin().toString() in my entry point and the incremental compile work. Maybe I need to reference somewhere in my generator all the classes used this way.

If you take the hello world example, I made this changes :

@JsonAutoDetect(
        getterVisibility = JsonAutoDetect.Visibility.NONE,
        creatorVisibility = JsonAutoDetect.Visibility.NONE,
        fieldVisibility = JsonAutoDetect.Visibility.ANY,
        isGetterVisibility = JsonAutoDetect.Visibility.NONE )
@JsonIgnoreProperties( value = {"greetin", "sdf"} )
public class GreetingResponseMixIn {
}
public class GreetingResponse {

    private String greeting;

    private String serverInfo;

    private String userAgent;

    public GreetingResponse(){}

    public GreetingResponse( String greeting, String serverInfo, String userAgent ) {
        this.greeting = greeting;
        this.serverInfo = serverInfo;
        this.userAgent = userAgent;
    }

    public String getGreeting() {
        return greeting;
    }

    public String getServerInfo() {
        return serverInfo;
    }

    public String getUserAgent() {
        return userAgent;
    }

}

Hello.java :

    @JsonMixIns( {
            @JsonMixIn( target = GreetingResponse.class, mixIn = GreetingResponseMixIn.class )
    } )
    public static interface GreetingResponseReader extends ObjectReader<GreetingResponse> {}

    ...

    public void onModuleLoad() {
        new GreetingResponseMixIn().toString();
        ....
    }

examples/pom.xml

    <!-- Plugins version -->
    <jetty.version>9.1.3.v20140225</jetty.version>
    <gwt-maven-plugin.version>2.8.0-beta1</gwt-maven-plugin.version>

    <!-- Dependencies version -->
    <gwt.version>2.8.0-beta1</gwt.version>

nmorel avatar May 28 '16 08:05 nmorel

I think I have the same issue

Just add

public static interface RestExceptionMapper extends ObjectMapper<RuntimeException> {}
private static final RestExceptionMapper restExceptionMapper = GWT.create(RestExceptionMapper .class);

To my EntryPoint class and SDM compilation fails with

         [ERROR] Errors in 'C:\Users\horto\AppData\Local\Temp\gwt-codeserver-6116945049615726828.tmp\com.jresearchsoft.booking.ft.admin.app.adminApp\compile-6\gen\com\google\web\bindery\event\shared\UmbrellaExceptionBeanJsonDeserializerImpl.java'
            [ERROR] Line 52: The constructor UmbrellaException() is not visible
            See snapshot: C:\Users\horto\AppData\Local\Temp\com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl3035152053544882270.java
         Tracing compile failure path for type 'com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl'
            [ERROR] Errors in 'C:\Users\horto\AppData\Local\Temp\gwt-codeserver-6116945049615726828.tmp\com.jresearchsoft.booking.ft.admin.app.adminApp\compile-6\gen\com\google\web\bindery\event\shared\UmbrellaExceptionBeanJsonDeserializerImpl.java'
               [ERROR] Line 52: The constructor UmbrellaException() is not visible
         [ERROR] Hint: Check that the type name 'com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl' is really what you meant
         [ERROR] Hint: Check that your classpath includes all required source roots
         [ERROR] Errors in 'C:\Users\horto\AppData\Local\Temp\gwt-codeserver-6116945049615726828.tmp\com.jresearchsoft.booking.ft.admin.app.adminApp\compile-6\gen\com\google\gwt\query\client\js\JsUtils_JsFunctionBeanJsonSerializerImpl.java'
            [ERROR] Line 30: T cannot be resolved to a type
            [ERROR] Line 33: serializer0 cannot be resolved
            [ERROR] Line 37: T cannot be resolved to a type
            [ERROR] Line 38: Type mismatch: cannot convert from Element to T
            See snapshot: C:\Users\horto\AppData\Local\Temp\com.google.gwt.query.client.js.JsUtils_JsFunctionBeanJsonSerializerImpl5246184019309637029.java
         Tracing compile failure path for type 'com.google.gwt.query.client.js.JsUtils_JsFunctionBeanJsonSerializerImpl'
            [ERROR] Errors in 'C:\Users\horto\AppData\Local\Temp\gwt-codeserver-6116945049615726828.tmp\com.jresearchsoft.booking.ft.admin.app.adminApp\compile-6\gen\com\google\gwt\query\client\js\JsUtils_JsFunctionBeanJsonSerializerImpl.java'
               [ERROR] Line 33: serializer0 cannot be resolved
               [ERROR] Line 38: Type mismatch: cannot convert from Element to T
               [ERROR] Line 30: T cannot be resolved to a type
               [ERROR] Line 37: T cannot be resolved to a type
         [ERROR] Hint: Check that the type name 'com.google.gwt.query.client.js.JsUtils_JsFunctionBeanJsonSerializerImpl' is really what you meant
         [ERROR] Hint: Check that your classpath includes all required source roots

foal avatar Nov 24 '16 12:11 foal

And yes, the "-noincremental" option works as workaround.

foal avatar Nov 24 '16 13:11 foal

I'm facing the same Exception when I compile my GWT 2.8.2 project (also when running super dev mode).

[INFO] --- gwt-maven-plugin:1.0-rc-9:compile (default-compile) @ gwt-storage-objectify-client --- [INFO] Compiling module com.project.App [INFO] Adding '94' new generated units [INFO] Tracing compile failure path for type 'com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl' [INFO] [ERROR] Errors in 'generated://1F08ECA3B1606808245F0A02107D1668/com/google/web/bindery/event/shared/UmbrellaExceptionBeanJsonDeserializerImpl.java' [INFO] [ERROR] Line 54: The constructor UmbrellaException() is not visible [INFO] See snapshot: /var/folders/bh/bph7c3k95sx91h59dkblcqkw0000gp/T/com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl4916228132515498650.java [INFO] [ERROR] Errors in 'generated://1F08ECA3B1606808245F0A02107D1668/com/google/web/bindery/event/shared/UmbrellaExceptionBeanJsonDeserializerImpl.java' [INFO] [ERROR] Line 54: The constructor UmbrellaException() is not visible [INFO] See snapshot: /var/folders/bh/bph7c3k95sx91h59dkblcqkw0000gp/T/com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl8516823328986300092.java [INFO] Tracing compile failure path for type 'com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl' [INFO] [ERROR] Errors in 'generated://1F08ECA3B1606808245F0A02107D1668/com/google/web/bindery/event/shared/UmbrellaExceptionBeanJsonDeserializerImpl.java' [INFO] [ERROR] Line 54: The constructor UmbrellaException() is not visible [INFO] [ERROR] Hint: Check that the type name 'com.google.web.bindery.event.shared.UmbrellaExceptionBeanJsonDeserializerImpl' is really what you meant [INFO] [ERROR] Hint: Check that your classpath includes all required source roots

And I found a weird way to fix it: just add dagger-compiler in your dependency

    <dependency>
      <groupId>com.google.dagger</groupId>
      <artifactId>dagger-compiler</artifactId>
      <version>2.13</version>
      <optional>true</optional>
    </dependency>

freddyboucher avatar Nov 26 '17 02:11 freddyboucher