How can I serialize a schema(or list of schema) from database?

I am trying to send a cart information when a user join the channel. But having some trouble serializing a cart information.

in my cart_channel.ex

def join("cart:" <> user_id, _params, %{assigns: %{current_user: user}} = socket) do
    # check if current user match client user
    if String.to_integer(user_id) == do
      # If authorized, return cart information
      {carts, total_items, total_price} = OrderManager.get_updated_carts(
      IO.puts("Cart channel join successful")

      socket =
        assign(socket, :carts, carts)
        |> assign(:total_items, total_items)
        |> assign(:total_price, total_price)

      send(self(), :send_cart)

      {:ok, socket}
      {:error, %{reason: "unauthenticated"}}

  def join("cart:" <> _user_id, _params, _socket) do
    {:error, %{reason: "unauthenticated"}}

  def handle_info(
        socket = %{assigns: %{carts: carts, total_items: total_items, total_price: total_price}}
      ) do
    push(socket, "cart", %{carts: carts, total_items: total_items, total_price: total_price})
    {:noreply, socket}

and got an error like this

[error] GenServer #PID<0.1082.0> terminating
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %MyApp.Checkout.Order{} of type MyApp.Checkout.Order (a struct), Jason.Encoder protocol must always be explicitly implemented.

How can I solve this?

You need to define @derive attribute in the Order schema, which tells which fields to translate to json.

Yes I tried for order schema but order schema has field type Money.Ecto.Amount.Type which is
schema that I don’t own.
Error says.

Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:

    Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
    Protocol.derive(Jason.Encoder, NameOfTheStruct)

But I am not familiar with Protocol. how can I do this?

From the doc, it would be something like this

defimpl Jason.Encoder, for: Test do
  def encode(value, opts) do, [:foo, :bar, :baz]), opts)