首页 > 解决方案 > EntityClass 中的 LocalDate 扰乱了 sonarQube

问题描述

我有带有 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;

}

谁能建议我们如何解决这个问题?

谢谢

标签: javajpajava-8sonarqubelocaldate

解决方案


如文档中所述, 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{..}

推荐阅读