[英]Fields in a “Serializable” class should either be transient or serializable
[英]Non entity variables: Fields in a “Serializable” class should either be transient or serializable
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出色地。 請讓我知道如何解決這個問題。
前任:
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() {
}}
對於下面的行,我將 sonarqube 問題視為關鍵
private Map<String, Object> metadata = new HashMap<>();
HashMap 是可序列化的,但 Map 不是,因為它沒有實現可序列化接口。 您可以在聲明時嘗試使用 HashMap 本身(不推薦)。
private HashMap<String, Object> metadata = new HashMap<>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.