3

我正在尝试使用 Distillery 创建我的 Phoenix 应用程序的版本,并且我已经覆盖了 Poison EncodersDateTimeNaiveDateTime匹配 API 要求。

当我运行时mix release,我的应用程序会编译,但在 .boot 生成期间出现错误。

这是堆栈跟踪:

$> mix release
warning: variable "aliases" does not exist and is being expanded to "aliases()", please use parentheses to remove the ambiguity or change the variable name
  mix.exs:12

warning: variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name
  mix.exs:13

==> Assembling release..
==> Building release helios:1.0.0 using environment dev
==> One or more direct or transitive dependencies are missing from
    :applications or :included_applications, they will not be included
    in the release:

    :ex_admin
    :floki
    :geo
    :guardian
    :json_web_token
    :mogrify
    :phoenix_pubsub
    :scrivener_ecto
    :timex
    :timex_ecto

    This can cause your application to fail at runtime. If you are sure
    that this is not an issue, you may ignore this warning.

==> Release failed, during .boot generation:
        Duplicated modules:
        'Elixir.Poison.Encoder.NaiveDateTime' specified in poison and helios
        'Elixir.Poison.Encoder.Ecto.DateTime' specified in ecto and helios

有没有办法在不遇到这个问题的情况下覆盖毒药编码器?

编辑:这是我拥有的编码器:

  defimpl Poison.Encoder, for: Ecto.DateTime do
    def encode(datetime, options) do

      dt = datetime |> Ecto.DateTime.to_erl
      |> Timex.Timezone.convert("UTC")
      |> Timex.format("{ISO:Extended}")
      |> elem(1)

      <<?", dt::binary, ?">>
    end
  end

  defimpl Poison.Encoder, for: NaiveDateTime do
    def encode(datetime, options) do

      dt = datetime
      |> Timex.Timezone.convert("UTC")
      |> Timex.format("{ISO:Extended}")
      |> elem(1)

      <<?", dt::binary, ?">>
    end
  end
4

1 回答 1

2

您可能想要实现该协议。文档给出了这个例子:

defimpl Poison.Encoder, for: Person do
  def encode(%{name: name, age: age}, options) do
    Poison.Encoder.BitString.encode("#{name} (#{age})", options)
  end
end

如果您不熟悉协议,请发布您的自定义编码器,我们可以帮助您了解协议。

编辑:

因此,经过大量挖掘,Poison 似乎不允许覆盖基本类型。这些已经在包中实现了。因此,当您在项目中覆盖它们时,您将创建两个版本的梁文件。

已经有这个问题针对这个问题开放。

于 2017-04-21T22:45:00.813 回答