ebean在尝试将json存储到db中时“找不到spijsonservice的服务实现”

oknrviil  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(336)

我正在尝试将模型的一部分作为json存储在我的db中。ebean应该有这个助手:

@DbJson
public Map<String, Object> jsonContent;

但是当我试图储存我的豆子时,它只有在我不给它时间的情况下才起作用 jsonContent 现场。当我试图设置它时,我得到以下错误:

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.ExceptionInInitializerError]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:178)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:343)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:341)
    at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:414)
    at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Caused by: java.util.concurrent.CompletionException: java.lang.ExceptionInInitializerError
    at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
    at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
    at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1592)
    at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ExceptionInInitializerError: null
    at io.ebeaninternal.server.type.ScalarTypeJsonMap.formatValue(ScalarTypeJsonMap.java:166)
    at io.ebeaninternal.server.type.ScalarTypeJsonMap.bind(ScalarTypeJsonMap.java:148)
    at io.ebeaninternal.server.type.ScalarTypeJsonMap$Clob.bind(ScalarTypeJsonMap.java:55)
    at io.ebeaninternal.server.deploy.BeanProperty.bind(BeanProperty.java:648)
    at io.ebeaninternal.server.persist.dml.DmlHandler.bindInternal(DmlHandler.java:226)
    at io.ebeaninternal.server.persist.dml.DmlHandler.bind(DmlHandler.java:198)
    at io.ebeaninternal.server.persist.dmlbind.BindableProperty.dmlBind(BindableProperty.java:54)
    at io.ebeaninternal.server.persist.dmlbind.BindableList.dmlBind(BindableList.java:62)
    at io.ebeaninternal.server.persist.dml.InsertMeta.bind(InsertMeta.java:162)
    at io.ebeaninternal.server.persist.dml.InsertHandler.bind(InsertHandler.java:97)
Caused by: java.lang.IllegalStateException: No service implementation found for SpiJsonService?
    at io.ebean.text.json.EJson.init(EJson.java:31)
    at io.ebean.text.json.EJson.<clinit>(EJson.java:23)
    at io.ebeaninternal.server.type.ScalarTypeJsonMap.formatValue(ScalarTypeJsonMap.java:166)
    at io.ebeaninternal.server.type.ScalarTypeJsonMap.bind(ScalarTypeJsonMap.java:148)
    at io.ebeaninternal.server.type.ScalarTypeJsonMap$Clob.bind(ScalarTypeJsonMap.java:55)
    at io.ebeaninternal.server.deploy.BeanProperty.bind(BeanProperty.java:648)
    at io.ebeaninternal.server.persist.dml.DmlHandler.bindInternal(DmlHandler.java:226)
    at io.ebeaninternal.server.persist.dml.DmlHandler.bind(DmlHandler.java:198)
    at io.ebeaninternal.server.persist.dmlbind.BindableProperty.dmlBind(BindableProperty.java:54)
    at io.ebeaninternal.server.persist.dmlbind.BindableList.dmlBind(BindableList.java:62)
[INFO] [08/06/2018 16:03:23.475] [Thread-2] [CoordinatedShutdown(akka://sbt-web)] Starting coordinated

我的豆子看起来像这样:

@Entity
@Table(name = "my_table")
public class MyBean extends AManageableModel {

    public static final Finder<Long, Configuration> find = new Finder<>(MyBean.class);

    @Constraints.Required
    public String name;

    @Constraints.Required
    @JsonProperty("some_property")
    public String someProperty;

    @DbJson
    @JsonProperty("json_content")
    public Map<String, Object> jsonContent;

}

当我使用下面的json在db中创建一行时,它可以工作(并且 jsonContentnull ):

{
  "name": "test 1",
  "some_property": "some property content"
}

但当我使用以下json时:

{
  "name": "test 1",
  "some_property": "some property content",
  "json_content": {
    "test":"test",
    "test2":"test2"
  }
}

它崩溃了(请参阅文章开头的完整stacktrace)。
序列化是使用jackson完成的:

Json.fromJson(jsonData, MyBean.class);
clj7thdc

clj7thdc1#

好吧,那么使用:

Map<String,String> jsonContent

而不是:

Map<String,Object> jsonContent

对我有效,所以我怀疑“object”需要扩展一些可序列化的东西。
编辑:所以,两年后我不得不使用 Map<String,Object> jsonContent 因为无法挽回的原因,同样的问题又出现了。这是一个肮脏的解决方案,在应用程序启动时称之为:

try {
  EJson.write(new Object());
} catch (IOException e1) {
  e1.printStackTrace();
}

这迫使 EJson 装载和问题消失。。。。但该死的是它很脏。

相关问题