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

How to control whether to generate inline list/map or not? #2

Closed
FishHawk opened this issue May 1, 2022 · 5 comments
Closed

How to control whether to generate inline list/map or not? #2

FishHawk opened this issue May 1, 2022 · 5 comments
Milestone

Comments

@FishHawk
Copy link

FishHawk commented May 1, 2022

My data classes:

data class MetadataDetailDto(
    val authors: List<String>,
    val collections: Map<String, Map<String, ChapterMetadataDto>>,
)
data class ChapterMetadataDto(
    val name: String,
    val title: String,
)

I would like to generate files like this:

authors = [ "author1",  "author2"]

[collections.collection1]
chapter1 = {name = "name", title = "title"}

But it generates this:

[[authors]]
 = "author1"

[[authors]]
 = "author2"

[collections]
collection1.chapter1.name = "name"
collection1.chapter1.title = "title"

So is there a way to control whether to generate inline list/map or not?

@valderman
Copy link
Owner

Currently this is not possible. I'm thinking a good API for this might be something like a generateInline<T>(Boolean) function in the config block to control this type by type, as well as a similar function to set the default generation style. Would this be a good solution?

@FishHawk
Copy link
Author

FishHawk commented May 5, 2022

There is a small problem with this solution: types like Map/List may sometimes need to be inlined and sometimes don't. But I think it's fine to let users handle these themselves.

Also, I have some suggestions:

  • Use inline style by default for better readability.
  • Provide an interface to control whether to keep inline Map/List oneline.

By the way, thanks for your library. Without it, I would have to introduce a huge dependency just for TOML.

@valderman
Copy link
Owner

Separated the invalid TOML generation part into its own issue (#12), so this issue can focus on the configurability part.

@valderman
Copy link
Owner

c2678aa introduces an interface for configuring serialization. It doesn't yet allow per-type configuration yet, but otherwise it covers most aspects of table/inline/multiline syntax. What do you think?

It does not change the default to prefer inline syntax, mostly to avoid changing defaults people might have come to expect.

@valderman
Copy link
Owner

Closing as fixed since there seem to be no complaints about the merged solution.

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