简体   繁体   中英

DSL-JSON: java.io.IOException: Unable to serialize provided object. Failed to find serializer for: class

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?

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());

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM