question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ] [dart-dio-next] Enum fallback values

See original GitHub issue

BuiltValue 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:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kuhnroyalcommented, Apr 10, 2022

@josh-burton This is fixed now 😃

0reactions
josh-burtoncommented, Dec 20, 2021

@kuhnroyal yeah that would be great. Letting the user choose which value is the fallback would be the ideal solution.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found