[REQ] [dart-dio-next] Enum fallback values
See original GitHub issueBuiltValue supports setting an enum entry as a fallback to use if the serialized enum value doesn’t exist.
This is great for backwards compatibility in APIs as an enum can fallback to an ‘unknown’ value.
## Describe the solution you'd like
In my API clients I generally modify the enum.mustache and inline_enum.mustache files to fallback to the first value.
@BuiltValueEnumConst({{#isInteger}}wireNumber: {{{value}}}{{/isInteger}}{{^isInteger}}wireName: r{{{value}}}{{/isInteger}}{{#-first}}, fallback: true{{/-first}})
A config flag could be added to enable this behaviour, or perhaps something more advanced like a config flag to determine which enum value to fallback to.
e.g. "enumFallbackValue": "unknown"
If an enum class is generated and has an "unknown" value, the fallback would be set on that value.
@kuhnroyal any thoughts?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to fallback on a enum if values don't match in Moshi
I have an enum class and would like it to fallback to a specific enum value if values don't match any of them....
Read more >Add a static `valueOfOrNull` method to Enums, similar to ...
A common use case is to try to parse an enum and expect null when dealing with an invalid value. Using try /...
Read more >UnknownValueImplementation Property - Business Central
Specifies the implementers used for ordinal values that are not included in the defined list of enum values.
Read more >ENUM - MariaDB Knowledge Base
Description. An enumeration. A string object that can have only one value, chosen from the list of values 'value1', 'value2', ..., NULL or...
Read more >Why TypeScript enums suck - LogRocket Blog
It's a group of named constant values that you can use within your code. Let's create an enum in TypeScript to represent the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@josh-burton This is fixed now 😃
@kuhnroyal yeah that would be great. Letting the user choose which value is the fallback would be the ideal solution.