-
Notifications
You must be signed in to change notification settings - Fork 624
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
Parsing case insensitive enums #209
Comments
Can this issue be treated as the more specific version of #33 ? |
@sandwwraith it does not seem that #33 gets implemented. Would this issue have a bigger chance on it's own? |
@henningBunk Perhaps, but I hope we would be able to implement #33 in one of the following releases |
What @JakeWharton implied in #33 is "this probably won't happen" |
See #2111 (comment) |
@sandwwraith Just wondering if this is the same thing this issue is talking about, but I have some json coming back like this: I want to parse that into an ENUM class, which will have BAD, GOOD, NEAR_GOOD.
However I see when it gets parsed, it is parsed as BAD, but I want it to match the json and be lowercase. |
It's about global configuration. Locally it is achievable with |
Hey @sandwwraith, just getting back to this now. |
What do you mean by "keep it as 'bad"? |
@sandwwraith So in the example I gave, the server sends us
Which will parse the JSON. Hope that makes sense. |
I still don't get it, as you already have uppercase enum in Kotlin. Maybe you want to use @Serializable
internal enum class State {
@JsonNames("good") GOOD,
@JsonNames("bad") BAD,
@JsonNames("near_good") NEAR_GOOD
} This will parse both |
@sandwwraith The way it is now, it is changing the JSON to show as BAD instead of reading it as 'bad'. |
Erm, do you know what |
Not familiar with the internal toString of enums, but I understand enum class, but you are making me question that now :D |
I suggest closing the conversation here, as it is entirely unrelated — what you see in the debugger and how enum classes are working in Kotlin is defined by Kotlin language, not by kotlinx.serialization. In short, their |
Ok apologies, I understood this issue incorrectly, thought it Was related to my problem. |
It allows decoding enum values in a case-insensitive manner. It does not affect CLASS kinds or encoding. It is one of the most-voted feature requests. Fixes #209
It allows decoding enum values in a case-insensitive manner. It does not affect CLASS kinds or encoding. It is one of the most-voted feature requests. Also enchance JsonNamingStrategy documentation. Fixes #209
This issue is open since 2018, there is still no solution to parse case insensitive enums? |
Oh sorry, I somehow missed that 🙈 Looking forward to test it! |
It allows decoding enum values in a case-insensitive manner. It does not affect CLASS kinds or encoding. It is one of the most-voted feature requests. Also enhance JsonNamingStrategy documentation. Fixes Kotlin#209
How can we parse case insensitive enums like we do on Jackson?
Example:
Result:
The text was updated successfully, but these errors were encountered: