Serializable Object.class

242 views Asked by At
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.

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.

How I can fix this codeSmeel by sonar lint?

1

There are 1 answers

6
Danilo Jakob On

The thing with Object fields is, those do not implement the Serializable interface. SonarQube is saying that you're trying to serialize a field, in this case Object register which does not implement the interface. For your register field you should use a custom class which implements the Serializable interface.

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.