Support new configuration that handles digit as a delimiter when converting to snake_case · Issue #2137 · circe/circe · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.
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.
The text was updated successfully, but these errors were encountered: