首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Quarkus native and org.kohsuke:github-api -无法反序列化异常

Quarkus native and org.kohsuke:github-api -无法反序列化异常
EN

Stack Overflow用户
提问于 2020-05-05 18:54:19
回答 3查看 268关注 0票数 1

我正在使用Quarkus native和org.kohsuke:github-api:1.111,当执行简单的new GitHubBuilder().withOAuthToken(ghToken).build();时,我在本地模式下看到Failed to deserialize异常。这在JVM模式下工作。

主要的问题可能是org.kohsuke:github-api还没有为原生模式做好准备。我仍然想问一下是否有解决这个问题的方法,也许是https://github.com/github-api/github-api/blob/master/src/main/java/org/kohsuke/github/GHMyself.java的一些jackson技巧(堆栈跟踪包含不能构造org.kohsuke.github.GHMyself的实例(不存在创建者,比如默认构造))。

异常详细信息:

代码语言:javascript
复制
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)

转制者详细信息:

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

为本机添加依赖项和quarkus.native.enable-https-url-handler属性

代码语言:javascript
复制
    <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>

更改GreetingResource

代码语言:javascript
复制
        GitHub github = new GitHubBuilder().withOAuthToken(ghToken).build();
        GHRepository ghRepo = github.getRepository("quarkusio/quarkus");
        return ghRepo.toString();

从GreetingResourceTest中删除.body(is("hello"))

运行mvn clean verify -Dnative

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-05-05 19:37:39

您还可以在任何类上使用@RegisterForReflection(targets = GHObject.class)

票数 1
EN

Stack Overflow用户

发布于 2020-05-05 19:06:39

我的猜测是,您将需要使用ReflectiveHierarchyBuildItem注册反射的所有GHObject层次结构。

所以这需要一个扩展。对于平台IMHO来说,这将是一个有用的补充。

票数 1
EN

Stack Overflow用户

发布于 2021-05-11 03:36:30

如果你在本机模式下运行,并且得到的错误是由于反射而导致的,那么用@RegisterForReflection注释你的类,并在你的类中添加一个无参数的构造函数,然后重新构建应用程序并运行,你的错误就会得到解决。

有关更多参考信息,请参阅link上的quarkus指南

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61611441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档