我有一个带有LocalDate的实体类,并且它自己根据JPA规范实现了可序列化的实体类。
一切都到现在为止,但是SonarQube现在抱怨:
Local Date is a Value type Class and should not be serialized.
它建议删除该字段或使其成为临时字段-在这种情况下,这两种方法都不起作用,因为我们需要将这些字段保留到数据库或某些内存中。
public class User implements Serializable{
//other attributes
@Column(name = "UPDATED_DATE")
private LocalDate updatedDate;
}
谁能建议我们如何解决这个问题?
谢谢
答案 0 :(得分:0)
如文档中所述, https://sonarcloud.io/coding_rules?open=squid%3AS3437&rule_key=squid%3AS3437
您可以将transient
放在date
字段的前面
或者您可以像这样抑制警告:
@SuppressWarnings("squid:S3437") //LocalDate is serializable
public class User implements Serializable{..}