无法编译java项目时,我使用DSL JSON序列化和序列化

r6hnlfcb  于 2023-10-14  发布在  Java
关注(0)|答案(1)|浏览(122)

我在谷歌上搜索过了。但没有任何结果。
我用的是java的jdk 8。当我编译这段代码的时候。我得到这个错误。
这是ResponseBody类。

public class ResponseBody {
    private String message;

    public ResponseBody(){
        this.message = null;
    }
    
    
    public ResponseBody(String message){
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
public static void main(String[] args) {
        try{
            DslJson dslJson = new DslJson<>();
            // ResponseBody is class with one property 'message'
            ResponseBody responseBody = new ResponseBody();
            responseBody.setMessage("hello saiful");

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            dslJson.serialize(responseBody, outputStream);
            byte[] serializedObject = outputStream.toByteArray();
            System.out.println("Object serialized to byte array");

            ByteArrayInputStream inputStream = new ByteArrayInputStream(serializedObject);
            responseBody = (ResponseBody) dslJson.deserialize(ResponseBody.class, inputStream);
            System.out.println("Object deserialized to byte array: "+responseBody.toString());

        }catch (Exception e){
            System.out.println(e);
        }

    }

在pom.xml中,我为DSL json添加了这个依赖项

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

编译错误:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Mono is required to run DSL compiler. Mono not detected or specified.
[ERROR] DSL compilation error
  Unable to setup DSL-JSON processing environment. Specify dsljson.loglevel=DEBUG for more information.
gwbalxhn

gwbalxhn1#

如果你使用的是Java JDK 8。然后在pom. xml中添加此依赖项,而不是给定的依赖项

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

相关问题