在尝试将Json存储在DB中时,Ebean'没有为SpiJsonService找到服务实现'

问题描述 投票:1回答:1

我想在我的数据库中将Json的一部分存储为Json。 Ebean应该有这个帮手:

@DbJson
public Map<String, Object> jsonContent;

但是当我尝试存储我的bean时,它只有在我不给它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

我的bean看起来像这样:

@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);
java mysql json ebean
1个回答
0
投票

好的,所以使用:

Map<String,String> jsonContent

代替 :

Map<String,Object> jsonContent

适合我,所以我怀疑“对象”需要扩展可序列化的东西。

© www.soinside.com 2019 - 2024. All rights reserved.