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 Yaml Naming Strategies #398

Closed
russellbanks opened this issue Mar 14, 2023 · 2 comments · Fixed by #400
Closed

Add Yaml Naming Strategies #398

russellbanks opened this issue Mar 14, 2023 · 2 comments · Fixed by #400
Labels
frozen help wanted Extra attention is needed

Comments

@russellbanks
Copy link
Contributor

russellbanks commented Mar 14, 2023

Describe the problem you'd like to solve

There is no naming strategy implementation, so @SerialName has to be applied to every variable in a data class:

@SerialName("PackageIdentifier") val packageIdentifier: String,
@SerialName("PackageVersion") val packageVersion: String

Describe the solution you'd like

A YamlNamingStrategy in the YamlConfiguration.

configuration = YamlConfiguration(
    yamlNamingStrategy = YamlNamingStrategy.PascalCase // CamelCase, SnakeCase, etc
)

Describe alternatives you've considered

@SerialName on every variable

Additional context

KotlinX Serialization recently added Json naming strategies in 1.5.0:

A long-awaited feature (Kotlin/kotlinx.serialization#33) is available in this release.
A new interface, JsonNamingStrategy and Json configuration property namingStrategy allow defining a transformation that is applied to all properties' names serialized by a Json instance.
There's also a predefined implementation for the most common use case: Json { namingStrategy = JsonNamingStrategy.SnakeCase }.
Check out the Kotlin/kotlinx.serialization#2111 for more details and documentation.

Json {
    namingStrategy = JsonNamingStrategy.SnakeCase // Predefined
}
Json {
    namingStrategy = JsonNamingStrategy { descriptor: SerialDescriptor, elementIndex: Int, serialName: String ->
        // Able to define custom naming strategy
    }
}

https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-naming-strategy

@charleskorn charleskorn added the help wanted Extra attention is needed label Mar 15, 2023
@charleskorn
Copy link
Owner

I don't have time to work on this myself, but I'd gladly review a PR for this if you're interested in putting one together.

@stale
Copy link

stale bot commented May 15, 2023

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues.
If this issue is still affecting you, please comment below within the next seven days.
Thank you for your contributions.

@stale stale bot added the stale label May 15, 2023
@charleskorn charleskorn added frozen and removed stale labels May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frozen help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants