Thoth.Json icon indicating copy to clipboard operation
Thoth.Json copied to clipboard

use of StringEnum attribute with Decode.Auto and Extra.withCustom

Open joprice opened this issue 7 months ago • 4 comments

When decoding a union annotated with StringEnum with Decode.Auto.generateDecoder, the generated decoder is simply parsing a string, so it does not fail on unknown enum cases.

Trying to work around this by passing a custom encoder to the extra parameter inadvertently overrides the decoding of all string types, since typeof<X>.FullName for a type with StringEnum is System.String. I have had similar problems with Erase unions, but unsure why.

Although I could avoid StringEnum altogether in most cases, I have some js code I'm interoping with which uses physical equality checks, and currently enum classes create a new instance of the class per instance of the enum, so I'm looking for a way to have a typesafe string wrapper that can have a validating decoder/encoder.

joprice avatar Jul 11 '24 23:07 joprice