Quarkus,Hibernate ORM和REST-RESTEASY008200:JSON绑定反序列化错误:

时间:2019-05-12 04:17:16

标签: java hibernate quarkus

我正在尝试创建一个使用Hibernate Panache和Rest的项目,类似于https://github.com/quarkusio/quarkus-quickstarts/tree/master/hibernate-orm-panache-resteasy上的快速入门。

如下图所示,当我尝试@Post扩展了PanacheEntity的实体时,出现以下错误:

  

javax.ws.rs.ProcessingException:RESTEASY008200:JSON绑定反序列化错误:无法创建实例

实体

@Entity
@Cacheable
class Trade extends PanacheEntity {

    @Column(length = 40, unique = true)
    String name;

}

其他资源

import javax.enterprise.context.ApplicationScoped;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@Path("/trades")
@ApplicationScoped
@Produces("application/json")
@Consumes("application/json")
public class TradeReporterResource {


    @POST
    @Transactional
    public Response add(Trade trade) {
        System.out.println("begin");
        //t.closePrice = trade.closePrice;
        System.out.println("persisting");
        trade.persist();
        System.out.println("persisted");
        return Response.ok(trade).build();
    }
}

Pom依赖项

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-bom</artifactId>
        <version>${quarkus.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-hibernate-orm-panache</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-jsonb</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-smallrye-openapi</artifactId>
    </dependency>
  </dependencies>

问题似乎出在Penache

当我从extends PanacheEntity实体中删除Trade时,至少我可以成功进行POST。

1 个答案:

答案 0 :(得分:1)

问题很简单,只需将Trade类设置为 public 类即可。

应该注意,这不是Quarkus限制,而是JSON-B限制(这要求反序列化的类具有公共或受保护的无参数构造函数-参见JSON-B规范的3.7节)< / p>