【问题标题】:DSL-JSON: java.io.IOException: Unable to serialize provided object. Failed to find serializer for: classDSL-JSON:java.io.IOException:无法序列化提供的对象。找不到序列化程序:类
【发布时间】:2018-04-16 12:35:46
【问题描述】:

我正在尝试使用DSL-JSON 运行其中一个示例。

我收到以下错误:

Exception in thread "main" java.io.IOException: Unable to serialize provided object. Failed to find serializer for: class dsl.test.Example$Model
    at com.dslplatform.json.DslJson.serialize(DslJson.java:2718)
    at dsl.test.Example.main(Example.java:231)

我只添加了对 pom.xml 的依赖:

    <dependency>
      <groupId>com.dslplatform</groupId>
      <artifactId>dsl-json</artifactId>
      <version>1.7.3</version>
    </dependency>

缺少什么?

【问题讨论】:

    标签: java json-deserialization json-serialization


    【解决方案1】:

    我曾经和你有同样的问题,我添加了这个设置来解决它。你可以试试这个:

    DslJson<Object> json = new DslJson<>(Settings.withRuntime().allowArrayFormat(true).includeServiceLoader());
    

    【讨论】:

    • 欢迎来到 SO,liyixn!此处不鼓励仅使用代码的答案,因为它们无法深入了解问题是如何解决的。请更新您的答案,说明您的代码如何解决手头的问题:)
    • 我也是 dsl-json 的新手,我不知道为什么它可以解决这个问题......它对我有用。所以我应该删除我的答案吗?
    • 有了这个withRuntime() 设置,你已经扼杀了Dsl-Json 的主要好处,即编译时代码生成。现在Dsl-Json会在运行时使用反射,影响性能基本上会不如Gson转换器。
    猜你喜欢
    • 2021-01-05
    • 1970-01-01
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多