0

I'm trying to use DSL-JSON running one of the examples.

I'm getting the following error:

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)

I've only added the dependency on my pom.xml:

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

What's missing?

Alessandro C
  • 3,310
  • 9
  • 46
  • 82

2 Answers2

0

I once had the same problem as you,and I add this setting to solve it.You may try this:

DslJson<Object> json = new DslJson<>(Settings.withRuntime().allowArrayFormat(true).includeServiceLoader());
liyixin
  • 33
  • 3
  • Welcome to SO, liyixn! Code-only answers are discouraged here, as they provide no insight into how the problem was solved. Please update your answer with an explanation of how your code solves the problem at hand :) – Joel Nov 05 '18 at 01:36
  • I am also new to the dsl-json,and i don't know why it could solve this problem......it just worked for me.So should i delete my answer? – liyixin Nov 05 '18 at 06:52
  • With this `withRuntime()` setting, you're already killing Dsl-Json's main benefit which is compile-time code generation. Now Dsl-Json will use reflection at runtime and will effect performance basically will be inferior to Gson converter. – Farid Feb 16 '20 at 10:10
0

Please make sure you have added dsl-json-processor dependency in your pom file

for example

<!-- https://mvnrepository.com/artifact/com.dslplatform/dsl-json-processor -->
<dependency>
    <groupId>com.dslplatform</groupId>
    <artifactId>dsl-json-processor</artifactId>
    <version>1.9.9</version>
</dependency>