当前位置: 首页 > 知识库问答 >
问题:

Quarkus原生代和组织:github-api - 未能反序列化异常

隗新霁
2023-03-14

我在玩Quarkus本机和org.kohsuke: github-api: 1.111,我看到在执行简单的new GitHubBuilder(). with OAuthToken(ghToken). build();时,无法在本机模式下反序列化异常。这在JVM模式下工作。

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

异常详情:

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)

复制者详细信息:

生成应用程序 - https://quarkus.io/guides/getting-started#bootstrapping-the-project

添加依赖项和quarkus.native。为本机启用https url处理程序属性

    <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>

更改欢迎资源

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

放下<代码>。body(is(" hello ")来自GreetingResourceTest

运行 mvn 干净验证 - 基因

共有3个答案

颛孙正谊
2023-03-14

如果您在本机模式下运行,并且错误是由于反射导致的。请使用<code>@RegisterForReflection</code>注释您的类。请在类中添加一个无参数构造函数,然后重新生成应用程序并运行。您的错误将得到解决。

如需更多参考,请参阅链接上的quarkus指南

相旭
2023-03-14

我猜您需要使用ReflectiveHierarchyBuildItem注册所有GHObject层次结构以进行反射

所以这需要延期。这将是对IMHO平台的有益补充。

车诚
2023-03-14

您还可以在任何类上使用@Register sterForReflection(目标=GHObject.class)

 类似资料:
  • 本文向大家介绍详解PHP序列化和反序列化原理,包括了详解PHP序列化和反序列化原理的使用技巧和注意事项,需要的朋友参考一下 0.前言 对象的序列化和反序列化作用就不再赘述,php中序列化的结果是一个php自定义的字符串格式,有点类似json. 我们在任何语言中设计对象的序列化和反序列化都需要解决几个问题 把某个对象序列化之后,序列化的结果有自描述的功能(从序列化的结果中知道这个对象的具体类型, 知

  • 我试图通过CLI反序列化保存为protobuf的文件(似乎是最容易做到的事情)。我不希望使用protoc进行编译,将其导入编程语言,然后读取结果。 我的用例:一个TensorFlow lite工具以原型格式输出了一些数据。我也在TensorFlow存储库中找到了原型定义。我只想快速阅读输出。具体来说,我正在从工具中获取消息。

  • 添加到DTO对象后,我想向服务器发送一个列表 从…起 当向控制器发送对象时,它会抛出

  • 试图在Java中使用protobuf反序列化消息,并得到以下异常。 原因:com.google.protobuf.InvalidProtocolBufferException:在解析协议消息时,输入意外地在字段中间结束。这可能意味着输入被截断,或者嵌入的消息错误报告了自己的长度。在com.google.protobuf.InvalidProtocolBufferException.Truncate

  • 我想写一个小应用程序来验证GitHub组织的成员。 应用程序应该将具体的GitHub org成员与数据库相匹配。当某个人不在数据库中时,它应该将其从GitHub组织中删除,等等。 我在使用GitHub API时的问题是,下面的请求只列出公共成员身份(因为我没有作为用户进行身份验证,但我不想这样做)。 https://api.github.com/orgs/_orgname_/members?cli

  • 我反映了JSON.NET JavaScriptDateTimeConverter类代码,复制了它,并将该类重命名为3DateTimeConverter,以便修改它以更精确和强类型的庄园格式化DateTime对象。 我让它根据JSON.NET输出强类型对象的方式输出一个类型,如: 运行JsonConverter的重写WriteJson方法来生成该值。 但是,当我尝试使用与相同转换器完全相同的设置反序