Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 覆盖毒物编码器_Elixir_Elixir Poison - Fatal编程技术网

Elixir 覆盖毒物编码器

Elixir 覆盖毒物编码器,elixir,elixir-poison,Elixir,Elixir Poison,我正在尝试使用Distillery创建我的Phoenix应用程序的发行版,我已经覆盖了DateTime和NaiveDateTime的毒药编码器,以符合API要求 当我运行mix-release时,我的应用程序会编译,但在.boot生成过程中出错 以下是stacktrace: $> mix release warning: variable "aliases" does not exist and is being expanded to "aliases()", please use pa

我正在尝试使用Distillery创建我的Phoenix应用程序的发行版,我已经覆盖了
DateTime
NaiveDateTime
的毒药编码器,以符合API要求

当我运行
mix-release
时,我的应用程序会编译,但在.boot生成过程中出错

以下是stacktrace:

$> 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
dempl-Poison.Encoder,用于:exto.DateTime-do
def encode(日期时间,选项)do
dt=datetime |>exto.datetime.to|erl
|>Timex.Timezone.convert(“UTC”)
|>Timex.format(“{ISO:Extended}”)
|>要素(1)

您可能想要实现该协议。文件给出了以下示例:

defimpl Poison.Encoder, for: Person do
  def encode(%{name: name, age: age}, options) do
    Poison.Encoder.BitString.encode("#{name} (#{age})", options)
  end
end
如果您不熟悉协议,请张贴您的自定义编码器,我们可以帮助您了解协议

编辑:

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


对这个问题已经有了公开的反对意见

这就是我目前所做的,但我得到了一个
复制模块
错误。如果我覆盖
DateTime
NaiveDateTime
的编码器,似乎
蒸馏厂
exrm
都不喜欢它。:/I我猜您的项目名为
:helios
。您收到的错误消息表明您的项目中有本地
Elixir.Poison.Encoder.NaiveDateTime
模块的副本。其他模块也一样。请检查以确保项目中没有这些模块。顺便说一句,
definpl
宏没有定义模块,它只实现协议。如果您没有自己的本地副本,那么我建议您尝试
mixeclean
并重新构建您的发行版。你也可以尝试一个混音版本。clean
我更新了帖子,加入了我的自定义编码器。我尝试了
mix-clean
mix-release.clean
并再次运行
mix-release
,但再次面临同样的错误。顺便说一句,谢谢你的帮助,谢谢!另外,我喜欢你在ExAdmin上的工作,我们也使用它:)我能想到的只有两件事可以解决这个问题。1,您在本地项目中的某个位置有一个源文件,其中包含
Poison.Encoder.NaiveDateTime
的模块定义,或2。您有一个梁文件正在运行,它将被mix release拾取。如果您已经在项目中对
Poison.Encoder.NaiveDateTime
执行了grep,那么您可以删除
deps
\u build
文件夹。然后运行
mix do deps.get,编译
,这样当我在
web
lib
文件夹中grep时,我就没有任何关于
Poison.Encoder.NaiveDateTime的模块定义了。但是,它们确实在我的
\u build
目录中显示为
\beam
文件,在
\u build/dev/lib/helios
\u build/dev/lib/poison
\u build/dev/consolidated