Add a generic encode/decode instance for sum types