Replies: 1 comment
-
Hm, that's not an easy one, because there is no reason for the deserializer to choose a tag over a string. One possibility is to have a contract do that for you. Contract shouldn't modify values in an arbitrary way, but however "normalization" is seen as ok. By normalization, I mean an operation that may chose a uniform representation, or do an automatic conversion, but doesn't change the content of the data. Concretely, this operation must be idempotent, which is just a pedantic word to say that if you apply it once, then applying the transformation again shouldn't do anything (a normalized value won't be changed). In particular, you can make an extended enum contract that also accepts strings, and if the input is a string, convert it to an enum before checking:
You can adapt if you don't care about specifying the list of allowed tags via the Otherwise you can indeed just traverse the record in a more traditional way using nested |
Beta Was this translation helpful? Give feedback.
-
I'd like to use an Enum contract with and imported YAML file. But there are not tags in YAML, only strings. Is there a way to deserialize the string into a tag. Or maybe I need to make a new function for it?
Beta Was this translation helpful? Give feedback.
All reactions