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 ChronoUnit ConfigReader #1117

Merged
merged 1 commit into from
Aug 29, 2021

Conversation

mdedetrich
Copy link
Contributor

This PR adds a ConfigReader for ChronoUnit. Not sure if a test is necessary since its reusing an existing javaEnumReader.

Copy link
Member

@ruippeixotog ruippeixotog left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @mdedetrich!

core/src/main/scala/pureconfig/BasicReaders.scala Outdated Show resolved Hide resolved
core/src/main/scala/pureconfig/BasicReaders.scala Outdated Show resolved Hide resolved
@mdedetrich
Copy link
Contributor Author

mdedetrich commented Aug 15, 2021

Thanks for the reply, I have a couple of questions

, we should probably use ConfigFieldMapping directly instead of a general function (in your specific case, it would be ConfigFieldMapping(ScreamingSnakeCase, KebabCase));

I just had a look at ConfigFieldMapping and from what I can tell reading the documentation it seems its only meant to apply to case class fields and not actual values (i.e. the rhs of the =), i.e.

myField=something

vs

my-field=something

Wouldn't it be confusing to use a ConfigFieldMapping for both keys and values? In my case I want the transformation to only apply to values and not keys/fields.

BasicReaders should include only ready-to-use reader instances, not instances that need to be "configured". We have a package pureconfig.configurable to hold readers that need to be constructed explicitly. Can you please move your baseJavaEnumReader there, renaming it to something like javaEnumReaderWithMapping

Agreed however should we still have a main implicit val chronoUnitReader: ConfigReader[ChronoUnit] in JavaTimeReaders? I believe there is a difference between configurable readers for things like date time formatters (where there are legitimately different unique formats for date time) and something like ChronoUnit where you have different cases for the same thing (i.e. half-days vs HALF_DAYS vs half_days). Wouldn't having a single kebab case (as you suggested) reader for ChronoUnit be more preferable since any other kind of configuration would be simply be non standard for typesafe config?

@ruippeixotog
Copy link
Member

Wouldn't it be confusing to use a ConfigFieldMapping for both keys and values? In my case I want the transformation to only apply to values and not keys/fields.

I'm afraid the documentation (and the class name itself) are a bit misleading. ConfigFieldMapping is used generally as a way to map between naming conventions, regardless of whether they're applied in keys or values. For example, besides case class field mapping, it's also used to choose the values for the disambiguation type field in sealed families (e.g. type = blue-car to select a BlueCar subclass). It's ok to use it for this use case 👍

Agreed however should we still have a main implicit val chronoUnitReader: ConfigReader[ChronoUnit] in JavaTimeReaders?

Yes, chronoUnitReader should remain in JavaTimeReaders just like you did, and its implementation should call our new configurable reader - I see no problem with a "non-configurable" reader being a particular instance of a configurable one (particularly one so general like a reader for all Java enums).

@mdedetrich
Copy link
Contributor Author

Thanks for the responses, I will work on the PR tomorrow!

@mdedetrich mdedetrich force-pushed the add-chronounit-reader branch 3 times, most recently from 6ace5b3 to 704df5c Compare August 16, 2021 16:22
@mdedetrich
Copy link
Contributor Author

@ruippeixotog I believe I have done the changes (along with re basing on master), let me know if anything else needs to be done.

Copy link
Member

@ruippeixotog ruippeixotog left a comment

Choose a reason for hiding this comment

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

Sorry for taking long to reply. Almost there, here are some final comments :)

core/src/main/scala/pureconfig/configurable/package.scala Outdated Show resolved Hide resolved
core/src/main/scala/pureconfig/BasicReaders.scala Outdated Show resolved Hide resolved
@mdedetrich mdedetrich force-pushed the add-chronounit-reader branch from 704df5c to b50148f Compare August 29, 2021 16:31
@mdedetrich mdedetrich force-pushed the add-chronounit-reader branch from b50148f to 69bb452 Compare August 29, 2021 17:18
@mdedetrich
Copy link
Contributor Author

mdedetrich commented Aug 29, 2021

@ruippeixotog I have resolved all of your remarks, I also ended up adding a round trip test for ChronoUnit

Copy link
Member

@ruippeixotog ruippeixotog 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, @mdedetrich!

@ruippeixotog ruippeixotog merged commit 7e536dd into pureconfig:master Aug 29, 2021
@mdedetrich mdedetrich deleted the add-chronounit-reader branch August 29, 2021 23:32
@mdedetrich
Copy link
Contributor Author

@ruippeixotog Sorry for disturbing but would it be possible to make a release of pureconfig with this change in there?

@ruippeixotog
Copy link
Member

Hi @mdedetrich, I'll do it next week 👍

@mdedetrich
Copy link
Contributor Author

Awesome, thank you!

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