Camelizing channel payloads

I need to camelize channel payloads for js purposes

I have tried 2 options so far, 1- writing a custom serializer and 2- wrapping Jason and passing it to json_library in config

In both cases, presence diffs and fields like phx_ref get camelized, which is probably not a good thing (or does it not matter?). One option is to figure out how to target and skip those, but since they are transported via the same means as app payloads, I’m guessing this would involve some hacky matching procedure, which does not seem too idiomatic.

I have read this article which basically describes the serializer approach, and has the downside mentioned above.

Surely many of you have been thru this, this can’t be that niche of a case (pun)

What is an idiomatic approach to camelizing channel payloads?

you can do it selectively on the client with your own serializer and delegate to ours for the decoding, then rewrite the payload keys unless the event starts with phx. You could also override channel.onMessage and handle it there the same way.

1 Like

thanks for the answer!

Which decoder do you mean by “ours”?

Also are there any snake_cased params used internally by phoenix.js? As in, if they’re only used by the server, is it safe to just camelize all ouput and underscore all input ?

I’d like to keep the serialization server side, as I will have > 1 clients. (Or are there caveats to that…?)