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

Pretty Printing an empty class adds a newline to json object #2502

Closed
luca992 opened this issue Nov 14, 2023 · 2 comments
Closed

Pretty Printing an empty class adds a newline to json object #2502

luca992 opened this issue Nov 14, 2023 · 2 comments
Labels

Comments

@luca992
Copy link

luca992 commented Nov 14, 2023

Describe the bug

Empty classes get a newline character added to the json object:

{
  "some_empty_class": {
  }
}

It's not very pretty 😅

To Reproduce

@Serializable
data class Test(
    @SerialName("some_empty_class") val someEmptyClass: SomeEmptyClass,
)

@Serializable
class SomeEmptyClass

println(Json{prettyPrint = true}.encodeToString(Test(SomeEmptyClass())))

Expected behavior
All other libraries I have used when pretty printing would output:

{
  "some_empty_class": {}
}

Environment

  • Kotlin version: [e.g. 1.9.20]
  • Library version: [e.g. 1.6.0]
@sandwwraith
Copy link
Member

Well, it is a matter of preference, mostly :) But I agree that since most libraries fold empty objects, we should likely do the same.

@luca992
Copy link
Author

luca992 commented Nov 14, 2023

Well, it is a matter of preference, mostly :) But I agree that since most libraries fold empty objects, we should likely do the same.

Yeah for sure haha. I just haven't seen other libraries do it that way 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants