我正在尝试创建一个使用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();
}
}
<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>
当我从extends PanacheEntity
实体中删除Trade
时,至少我可以成功进行POST。
答案 0 :(得分:1)
问题很简单,只需将Trade
类设置为 public 类即可。
应该注意,这不是Quarkus限制,而是JSON-B限制(这要求反序列化的类具有公共或受保护的无参数构造函数-参见JSON-B规范的3.7节)< / p>