1
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?

Valdy B
  • 151
  • 1
  • 1
  • 9
  • 2
    My recommendation is to deactivate the rule. Trying to enforce serializable types at compile time via declarations contradicts common practice and will turn out to be impossible in a lot of scenarios. See [this answer](https://stackoverflow.com/a/31117279/2711488) and also [this comment](https://stackoverflow.com/questions/31115005/whats-the-best-way-of-ensuring-a-function-argument-is-serializable/31117279#comment50251549_31115005) – Holger Oct 05 '20 at 12:23

1 Answers1

0

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.

Danilo Jakob
  • 71
  • 1
  • 6