How to specify that fields are not added to the toString when JAVA Lombok uses @ Data

topic description

how to specify that fields are not added to toString

when JAVA Lombok uses @ Data

related codes

/ / Please paste the code text below (do not replace the code with pictures)

import lombok.Data;
import java.io.Serializable;

@Data
public class User implements Serializable {

    private Integer id;

    private String name;

    private String code;

}

for example, the User class now uses @ Data, when using new User (). ToString (), the output string has three id/name/code fields in it, but what should I do if I don"t want the code field in it?

Feb.21,2022

exclude @ ToString (exclude= "code")


By default, all non-static fields will be printed. If you want to skip some fields, you can annotate these fields with @ ToString.Exclude


annotate @ ToString.Exclude directly above the fields to be excluded

Menu