You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when using the default options for generic encoding and try to encode A { tag = 2 } the result is {"tag":2}, because the field tag overwrote the actual constructor tag A
The text was updated successfully, but these errors were encountered:
The default sum encoding is TaggedObject with tagFieldName and its docs say
So make sure that your record doesn't have a field with the same label as the tagFieldName. Otherwise the tag gets overwritten by the encoded value of that field!
So either we can somehow try to point out that in the docs more clearly (I have no idea how though), or change the default sum encoding to e.g. ObjectWithSingleField, which doesn't have such limitations. That however would be a very big breaking change (silently changing stuff for people, i.e. only proper encoding tests would find the change!), so I'm hesitant.
I'd advice you
to write instances out, like toEncoding = toEncoding myOptions (which you should do anyway, so toEncoding is derived, and not using toJSON), where myOptions = defaultOptions { ... }
write encoding (or better roundtrip) tests
Then you can change the "tag", or the sum encoding for a type with tag field.
Consider a type like this:
when using the default options for generic encoding and try to encode
A { tag = 2 }
the result is{"tag":2}
, because the fieldtag
overwrote the actual constructor tagA
The text was updated successfully, but these errors were encountered: