简体   繁体   English

可序列化的 Object.class

[英]Serializable Object.class

public class RegisterRequest implements Serializable {

    @NotNull(message = "Register may not be null")
    private Object register;

}

I got codeSmell from sonarLing SonarLint: Make "data" transient or serializable.我从 sonarLing SonarLint: Make "data" transient or serializable.得到了 codeSmell SonarLint: Make "data" transient or serializable.

Because I have Object.class I can't add in this class implements Serializable also I can't transient because I need this object serialize.因为我有Object.class我不能在这个类中添加implements Serializable也我不能transient因为我需要这个对象序列化。

How I can fix this codeSmeel by sonar lint?我如何通过声纳棉绒修复此代码?

The thing with Object fields is, those do not implement the Serializable interface.对象字段的问题是,那些不实现Serializable接口。 SonarQube is saying that you're trying to serialize a field, in this case Object register which does not implement the interface. SonarQube 是说您正在尝试序列化一个字段,在这种情况下是未实现接口的Object register For your register field you should use a custom class which implements the Serializable interface.对于您的register字段,您应该使用实现Serializable接口的自定义类。

Because of this SonarQube is telling you that you should either let Object implement the Serializable interface (which you can't) or mark it with transient .因为这个 SonarQube 告诉你,你应该让Object实现Serializable接口(你不能)或用transient标记它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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