Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip null field with lombok @ToString

Tags:

lombok

I found with no succes the simple way to use lombok @toString with the skip null field behaviour.

I think create my own toString function for all function using the aspect programmation. Like that i can chek all null field and skip that.

But it is the good practice, or lombok @toString has one option to do that simply?

Best Regards

like image 712
patrick BAK Avatar asked Feb 09 '19 08:02

patrick BAK


People also ask

How do I exclude fields from ToString Lombok?

If you want to skip some fields, you can annotate these fields with @ToString. Exclude . Alternatively, you can specify exactly which fields you wish to be used by using @ToString(onlyExplicitlyIncluded = true) , then marking each field you want to include with @ToString.

What does @ToString annotation do?

The @ToString annotation generates an implementation for the toString() method where the class name, along with each field in order — separated by commas — is printed. By default, the field names will be printed. Passing includeFieldNames=false to the annotation will print the field values but not the field names.

What is @ToString Lombok?

The Lombok @ToString annotation generates an implementation for the toString method and by default, it'll print your class name, along with each field, in order, separated by commas. By default non-static fields are excluded in generated toString() .

Does Lombok @data include ToString?

Yes, @Data implies @EqualsAndHashCode and @ToString .


1 Answers

It's an open issue on Lombok, so it's not part of implementation yet. see #1297.

like image 157
Pushkar Adhikari Avatar answered Sep 27 '22 18:09

Pushkar Adhikari