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

Add toLines() trait #2

Closed
sormuras opened this issue Feb 22, 2021 · 5 comments
Closed

Add toLines() trait #2

sormuras opened this issue Feb 22, 2021 · 5 comments

Comments

@sormuras
Copy link
Contributor

Interested in adding a trait for a multi-line toString() variant that indents each nested component on a best-effort basis?

Something similar to https://sormuras.github.io/blog/2020-05-06-records-to-text-block.html

@forax
Copy link
Owner

forax commented Feb 22, 2021

Hi Christian,
yes, maybe with a syntax closer to JSON, with the record name in comment ?

@sormuras
Copy link
Contributor Author

Ho! 🤓

Sure, will create a PR later. Perhaps one with taking arguments for the style and indentation strings...

.toLines(Style.JSON, " ") {...}

Return type?

  • String (with configurable new line character, of course)
  • List<String>
  • Stream<String>

@forax
Copy link
Owner

forax commented Feb 22, 2021

I wonder if a String is not enough.
I'm not a fan of toLines(JSON), i would prefer two methods, one toJSON() and one toHumanReadableJSONLike() which uses JSON + comment + several lines as format

@forax
Copy link
Owner

forax commented Feb 22, 2021

see https://github.com/forax/record-util/blob/master/src/main/java/com/github/forax/recordutil/JSONTrait.java for a skeleton implementation (no recursion, etc)

@forax
Copy link
Owner

forax commented Feb 23, 2021

I've implemented a version that generates a human readable JSON
see a5c8fe6

@forax forax closed this as completed Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants