Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Generic of list variable Serializable

How can I make private List <T> list; or private Map<String, Value> unknownData; serializable? These are variable in my class whose parent is serializable but SonarQube is complaining about transient or Serializable change

myClass.java

public class MyClass implements Serializable {
  private static final long serialVersionUID = 0L;
  protected  List<T>  list = new ArrayList<T>();

Screen shot of SonarQube complaint

like image 662
koala421 Avatar asked Mar 09 '23 04:03

koala421


1 Answers

In the class(es) declaration(s), extend the types with Serializable.

For example :

public class MyClass<T extends Serializable>{ ...

and

public class MyOtherClass<Value extends Serializable>{ ...
like image 183
davidxxx Avatar answered Mar 29 '23 05:03

davidxxx