Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsoncolor does not colorize elements that implement MarshalJSON #17

Closed
neilotoole opened this issue Feb 25, 2022 · 1 comment
Closed

Comments

@neilotoole
Copy link
Owner

Currently, if an element implements MarshalJSON, jsoncolor will delegate the byte encoding to that method, and then use those returned bytes. Instead, we should allow the MarshalJSON method to return bytes, and then re-parse those into a v interface{}, which should then be passed to the usual jsoncolor funcs.

neilotoole added a commit that referenced this issue Mar 3, 2022
Fixes #17 - RawMessage and json.Marshaler are now colorized
@neilotoole
Copy link
Owner Author

The same issue affected handling of RawMessage. The PR does handles colorization of both (in practice, the encodeJSONMarshaler gets the JSON bytes and delegates to encodeRawMessage), but with the unfortunate side-effect that keys can be re-ordered in the output.

A preferable solution would be an implementation of encodeRawMessage that decodes the raw tokens and then re-encodes (with indent/color) without marshaling into a map at any time (as the map will lose the key order). This is beyond scope though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant