Quarkus native and org.kohsuke:github-api - Failed to deserialize exception

江枫思渺然 提交于 2021-01-28 20:30:42

问题


I'm playing with Quarkus native and org.kohsuke:github-api:1.111 and I see Failed to deserialize exception in native mode when doing simple new GitHubBuilder().withOAuthToken(ghToken).build();. This works in JVM mode.

The main problem is probably the fact that org.kohsuke:github-api is not ready for native mode. I still want to ask if there are any options to workaround this, maybe some jackson tricks for https://github.com/github-api/github-api/blob/master/src/main/java/org/kohsuke/github/GHMyself.java (stacktrace contains Cannot construct instance of org.kohsuke.github.GHMyself (no Creators, like default construct, exist)).

Exception details:

2020-05-05 10:47:06,891 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /hello failed, error id: a71018e5-de46-43a0-a194-80bd0b477f3d-1: org.jboss.resteasy.spi.UnhandledException: org.kohsuke.github.HttpException: Server returned HTTP response code: 200, message: '200 OK' for URL: https://api.github.com/user
...
Caused by: java.io.IOException: Failed to deserialize {"login":"rsvoboda","id":925259,"node_id":"MDQ6VXNlcjkyNTI1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/925259?v=4","gravatar_id":"","url":"https://api.github.com/users/rsvoboda","html_url":"https://github.com/rsvoboda","followers_url":"https://api.github.com/users/rsvoboda/followers","following_url":"https://api.github.com/users/rsvoboda/following{/other_user}","gists_url":"https://api.github.com/users/rsvoboda/gists{/gist_id}","starred_url":"https://api.github.com/users/rsvoboda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsvoboda/subscriptions","organizations_url":"https://api.github.com/users/rsvoboda/orgs","repos_url":"https://api.github.com/users/rsvoboda/repos","events_url":"https://api.github.com/users/rsvoboda/events{/privacy}","received_events_url":"https://api.github.com/users/rsvoboda/received_events","type":"User","site_admin":false,"name":"Rostislav Svoboda","company":"JBoss by Red Hat by IBM","blog":"https://twitter.com/r_svoboda","location":"Brno, Czech Republic","email":"rsvoboda@redhat.com","hireable":null,"bio":null,"public_repos":138,"public_gists":3,"followers":18,"following":2,"created_at":"2011-07-19T12:18:08Z","updated_at":"2020-04-29T14:38:31Z"}
    at org.kohsuke.github.GitHubResponse.parseBody(GitHubResponse.java:87)
    at org.kohsuke.github.GitHubClient.lambda$fetch$0(GitHubClient.java:146)
    at org.kohsuke.github.GitHubClient.createResponse(GitHubClient.java:404)
    at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:358)
    ... 37 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.kohsuke.github.GHMyself` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (String)"{"login":"rsvoboda","id":925259,"node_id":"MDQ6VXNlcjkyNTI1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/925259?v=4","gravatar_id":"","url":"https://api.github.com/users/rsvoboda","html_url":"https://github.com/rsvoboda","followers_url":"https://api.github.com/users/rsvoboda/followers","following_url":"https://api.github.com/users/rsvoboda/following{/other_user}","gists_url":"https://api.github.com/users/rsvoboda/gists{/gist_id}","starred_url":"https://api.github.com/users/rsvobod"[truncated 734 chars]; line: 1, column: 2]
    at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1592)
    at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1058)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
    at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1719)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1261)
    at org.kohsuke.github.GitHubResponse.parseBody(GitHubResponse.java:84)

Reproducer details:

generate the app - https://quarkus.io/guides/getting-started#bootstrapping-the-project

add dependencies and quarkus.native.enable-https-url-handler propery for native

    <dependency>
      <groupId>org.kohsuke</groupId>
      <artifactId>github-api</artifactId>
      <version>1.111</version>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jackson</artifactId>
    </dependency>
...
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
        <quarkus.native.enable-https-url-handler>true</quarkus.native.enable-https-url-handler>
      </properties>

change GreetingResource

        GitHub github = new GitHubBuilder().withOAuthToken(ghToken).build();
        GHRepository ghRepo = github.getRepository("quarkusio/quarkus");
        return ghRepo.toString();

drop .body(is("hello")) from GreetingResourceTest

run mvn clean verify -Dnative


回答1:


You can also use @RegisterForReflection(targets = GHObject.class) on any of your classes




回答2:


My guess is that you will need to register all the GHObject hierarchy for reflection using a ReflectiveHierarchyBuildItem.

So that requires an extension. It would be a useful addition for the Platform IMHO.



来源:https://stackoverflow.com/questions/61611441/quarkus-native-and-org-kohsukegithub-api-failed-to-deserialize-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!