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

Support new configuration that handles digit as a delimiter when converting to snake_case #2137

Open
LimJiGyu opened this issue May 12, 2023 · 1 comment

Comments

@LimJiGyu
Copy link

LimJiGyu commented May 12, 2023

There is a need for a new configuration logic that can handle a digit as a delimiter, including capital letters.

For Instance when converting PascalCase to snake_case, we should transform it as follows.
AddressLine1 -> address_line1 (incorrect)
AddressLine1 -> address_line_1 (correct)
(I think this online converting tool is using the logic above. Try some cases in this site Text to Snake Case Online Conterter)

However, the existing configuration in renaming object (modules/core/shared/src/main/scala-3/io/circe/derivation/renaming.scala) does not support this particular case.

Therefore, I would like to suggest the addition of an option to utilize this new configuration, allowing for a different swap pattern like the one described above.
existing:
private val basePattern: Pattern = Pattern.compile("([A-Z]+)([A-Z][a-z])") private val swapPattern: Pattern = Pattern.compile("([a-z\\d])([A-Z])")

new option:
private val basePattern: Pattern = Pattern.compile("([A-Z]+)([A-Z][a-z])") private val swapPattern: Pattern = Pattern.compile("([a-z\\d])([\\dA-Z])")

Furthermore, even if such selectable options are provided, I believe it would be ideal to offer them in an extended form that does not affect the existing Configuration we currently use.

If you have any recommendations or suggestions, I would greatly appreciate your input. Thank you.

@LimJiGyu LimJiGyu changed the title Add new configuration that handles digit as a delimiter when converting to snake_case Support new configuration that handles digit as a delimiter when converting to snake_case May 12, 2023
@Lasering
Copy link
Contributor

Configuration.withSnakeCaseMemberNames and Configuration.withSnakeCaseConstructorNames and just setting transformMemberNames and transformConstructorNames respectively. You are free to define much more complicated logic using withTransformMemberNames and withTransformConstructorNames.

Changing the existing renaming.snakeCase would be a breaking change.

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