Custom Socket JSON Serializer

I need to stringify my id’s before sending them to the client via channel.

IIUC this involves 2 steps:

  1. Creating a serializer module that implements @behaviour Phoenix.Socket.Serializer
  2. Configuring sockets in the endpoint to use it

Here’s step 1, the serializer module gist

Step 2:

  socket "/user_socket", ChataWeb.UserSocket,
    websocket: [
      serializer: [{Chata.Serializer.Socket.JSON}]
    longpoll: false

I tried these answers

How do you get this to work?

Had to add

  def encode_to_iodata!(term) do
    |> encode_integers()
    |> Jason.encode_to_iodata!()