Reputation: 715
Fields in a "Serializable" class should either be transient or serializable is possible to fix any entity/class is used in another class, but it occurs when List/ Map is declared in a dto class which can't be even made as transient as well. please let me know how to fix this.
Ex:
public class CustomMetadataDTO implements Serializable {
private UUID id;
private Map<String, Object> metadata = new HashMap<>();
private UUID fieldGroupId;
private Integer order;
public CustomMetadataDTO(Map<String, Object> metadata, Integer order) {
this.metadata = metadata;
this.order = order;
}
public CustomMetadataDTO() {
}}
for below line I get the sonarqube issue as critical
private Map<String, Object> metadata = new HashMap<>();
Upvotes: 0
Views: 885
Reputation: 778
HashMap is serializable but Map is not as it does not implement Serializable interface. You can try using HashMap itself while declaring (not recommended).
private HashMap<String, Object> metadata = new HashMap<>();
Upvotes: 1