Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Improve documentation for @ToString #2988

Closed
michaelboyles opened this issue Oct 7, 2021 · 2 comments
Closed

[DOCS] Improve documentation for @ToString #2988

michaelboyles opened this issue Oct 7, 2021 · 2 comments
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail documentation Addressing this item primarily involves writing docs / updating the website
Milestone

Comments

@michaelboyles
Copy link

Similar to #2870, which I also raised, I have an answer on Stack Overflow related to @ToString which I noticed has 9000 views. It seems to be the case that people are under the impression that it may be possible to change the format of the string generated by @ToString.

Since people are obviously searching for this a lot, I think it would be worth making it clearer in the documentation that this is not possible.

Current

Any class definition may be annotated with @ToString to let lombok generate an implementation of the toString() method. By default, it'll print your class name, along with each field, in order, separated by commas.

Suggested change

Annotating a class with @ToString will cause lombok to generate an implementation of the toString() method. There is configuration to specify whether field names should be included but otherwise the format is fixed: the class name followed by parentheses containing fields separated by commas, e.g. MyClass(foo=123, bar=234).

@rzwitserloot
Copy link
Collaborator

Could do. But we have some open issues on allowing you some flexibility. The problem is, the amount of use cases are staggering and it quickly spins out of control into something that takes 5 pages of manual and involves inventing a regex-like templating engine. All that just for some toString stuff. So we keep holding off.

Maybe you're right, and we should just update the docs now. We can always change it again if we do come up with a simple yet flexible solution.

@rzwitserloot rzwitserloot added accepted The issue/enhancement is valid, sensible, and explained in sufficient detail documentation Addressing this item primarily involves writing docs / updating the website labels Oct 7, 2021
@rzwitserloot rzwitserloot added this to the next-version milestone Oct 7, 2021
@michaelboyles
Copy link
Author

Yeah, could get complex. FWIW, I've always been perfectly happy with the format lombok spits out, and supporting a more specific set of use-cases seems beyond the scope of the problems lombok usually sets out to solve. Obviously if there's an elegant solution which increases flexibility without ballooning in complexity then everyone's happy.

I forgot to include the StackOverflow post in question. It's here: How to change the output of the method generated by Lombok's @ToString?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail documentation Addressing this item primarily involves writing docs / updating the website
Projects
None yet
Development

No branches or pull requests

2 participants