问题描述
这是我收到的错误/堆栈跟踪:
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {:safe,["<!DOCTYPE html>\...</html>\n"]} of type Tuple,Jason.Encoder protocol must always be explicitly implemented. This protocol is implemented for the following type(s): Ecto.Association.NotLoaded,Ecto.Schema.Metadata,MixAudit.Advisory,MixAudit.Vulnerability,MixAudit.Report,MixAudit.Dependency,Date,BitString,Jason.Fragment,Any,Map,NaiveDateTime,List,Integer,Time,DateTime,Decimal,Atom,Float
code: |> post("/api/v1/horses",Jason.encode!(params))
stacktrace:
(jason 1.2.1) lib/jason.ex:199: Jason.encode_to_iodata!/2
(phoenix 1.5.4) lib/phoenix/controller.ex:776: Phoenix.Controller.render_and_send/4
(phoenix 1.5.4) lib/phoenix/endpoint/render_errors.ex:78: Phoenix.Endpoint.RenderErrors.instrument_render_and_send/5
(phoenix 1.5.4) lib/phoenix/endpoint/render_errors.ex:64: Phoenix.Endpoint.RenderErrors.__catch__/5
(phoenix 1.5.4) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
test/my_app_web/controllers/api/v1/horses_controller_test.exs:100: (test)
被编码为json的地图参数具有以下形状:
params = %{
"animals" => ["horses"],"type" => "mammal","user" => %{
"id" => "1","email" => "[email protected]"
}
}
令人困惑的是,“ post”是指json端点-路由器通过具有plug(:accepts,["json"])
的“ api”管道进行管道传输-这组测试中的其他测试似乎没有此问题。我一直在进行基本的调试(将代码行注释掉,进行IO.puts等),但是我仍然似乎无法隔离出失败的地方。任何想法可能是什么原因,或者是否有更好的调试方法?其他控制器测试似乎还可以,所以我正在调查这些问题,但是此问题目前还没有任何意义。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)