I am new to Elixir and Phoenix so this problem is probably fairly trivial. My Phoenix application is an API client and I am trying to create a struct to model the data I will receive from the REST endpoint. I basically followed the small example on the Poison GitHub page to create my module:
defmodule ElixirServer.CurrentlyReprModule do
@derive [Poison.Encoder]
defstruct [:id, :time, :summary, :icon, :nearestStormDistance,
:nearestStormBearing, :precipIntensity, :precipProbability, :temperature,
:apparentTemperature, :dewPoint, :humidity, :pressure, :windSpeed, :windGust,
:windBearing, :cloudCover, :uvIndex, :visibility, :ozone]
end
The module is located under lib/elixir_server/ (is this even the best location for this type of file?).
My problem is when I try to compile the file I get this error:
(CompileError) lib/elixir_server/currently_repr_module.ex:2: module Poison.Encoder is not loaded and could not be found
When I try to run iex -S mix I get a similar error:
(UndefinedFunctionError) function Poison.Encoder.__using__/1 is undefined or private
Poison is included in the dependencies in mix.exs. How do I resolve this error?
Your issue might be with the structure of your project or where you are invoking commands from. Here is a zero to phoenix example of how to get a struct that is json encoded using Jason
lib/poison_demo_web/router.ex
lib/poison_demo_web/controllers/repr_controller.ex
lib/repr/repr.ex