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

HOCON: parse strings into integers and booleans if possible #1795

Merged

Conversation

tobiaslieber
Copy link
Contributor

HOCON suggest that parsers should apply certain automatic conversions, especially when reading integers/numbers or booleans from strings (1).

This is an attempt to resolve the most pressing issues that would resolve #1439 .
This PR changes parsing so that it now relies on the parsing capabilities for the Config class, and not on the obtained ConfigValues.

This PR does not claim to cover all automatic conversions mentioned in 1, but is focused on parsing numbers and booleans from strings only.

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, great work! I don't have objections to it except a few comments

@tobiaslieber
Copy link
Contributor Author

@sandwwraith Thank you for the review. I think I addressed your concerns.

fun `deserialize map with integers`() {
val configString = """m = { 2: 1, 4: 3 }"""
val obj = deserializeConfig(configString, WithMap.serializer())
with(obj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls remove with also here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

fun `deserialize map with integers as strings`() {
val configString = """m = { "2": "1", "4":"3" }"""
val obj = deserializeConfig(configString, WithMap.serializer())
with(obj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sorry for not having checked this thoroughly before.

Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@sandwwraith sandwwraith merged commit 77aa167 into Kotlin:dev Dec 20, 2021
@sandwwraith sandwwraith mentioned this pull request Dec 20, 2021
11 tasks
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

Successfully merging this pull request may close these issues.

2 participants