cbor
cbor copied to clipboard
feature: Option to disable built-in support for BinaryMarshaler and BinaryUnmarshaler
Is your feature request related to a problem? Please describe.
I'm introducing CBOR as an alternative to an existing JSON codec based on the stdlib encoding/json package, whose marshal and unmarshal behaviors are not at all affected by whether or not a value's type implements BinaryMarshaler or BinaryUnmarshaler. Users can today be successfully encoding and decoding types that implement these interfaces to and from JSON. If they flip the switch to instead use CBOR, today, CBOR may produce or expect something entirely different in structure and content from the current JSON.
Describe the solution you'd like
Encode and Decode options to ignore BinaryUnmarshaler and BinaryMarshaler on decode and encode.
Describe alternatives you've considered
This is a built-in behavior, so I don't think it can be disabled through an existing extension point. Over time, I hope efforts like https://github.com/fxamacker/cbor/issues/507 will make it possible both for users to set custom marshal/unmarshal behaviors on interface types that they do not control, and that the BinaryMarshaler built-in could be implemented with (and configurable by) the same mechanism.
Additional context
I implemented what I am proposing in https://github.com/fxamacker/cbor/pull/526.
Thanks Ben! :tada: Closed by #526.