Can't make work JSONB with Ecto model in Phoenix
<p>I have been trying to save JSON in jsonb column in postgresql, I've tried <a href="http://www.learningwithjb.com/posts/adding-a-json-field-with-ecto" rel="noreferrer">this</a> tutorial and also started reading Ecto API as well as Postgrex but can't make it work, a working example would enlight me :) so far I have added this to my config</p>

<pre><code>config :bonsai, Bonsai.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "demo",
  password: "demo123",
  database: "bonsai_test",
  hostname: "localhost",
  pool: Ecto.Adapters.SQL.Sandbox,
  extensions: [{Postgrex.Extensions.JSON, [library: Poison]}]
</code></pre>

<p>This is my Model</p>

<pre><code>defmodule Bonsai.Organization do
  use Bonsai.Web, :model

  schema "organizations" do
    field :name, :string
    field :currency, :string
    field :tenant, :string
    field :info, Bonsai.Json.Type, default: %{}
    field :settings, :map, default: %{} #, :map#, Bonsai.Json.Type

    timestamps
  end

  @required_fields ~w(name currency tenant)
  @optional_fields ~w()

  def changeset(model, params \\ :empty) do
    model
    |&gt; cast(params, @required_fields, @optional_fields)
  end
end
</code></pre>

<p>And the definition of types is in <code>web/utils/json.ex</code></p>

<pre><code>defmodule Bonsai.Json.Type do
  @behaviour Ecto.Type
  alias Bonsai.Json

  def type, do: :json

  def load({:ok, json}), do: {:ok, json}
  def load(value), do: load(Poison.decode(value))

  def dump(value), do: Poison.encode(value)
end
</code></pre>

<p>When I try to test I can't get to save the info or settings map</p>

<pre><code>defmodule Bonsai.OrganizationTest do
  use Bonsai.ModelCase

  alias Bonsai.Organization

  @valid_attrs %{currency: "USD", name: "Home", tenant: "bonsai",
    settings: %{"last_save" =&gt; true},
    info: %{"address" =&gt; "Samaipata", "mobile" =&gt; "73732677", "age" =&gt; 40}
  }
  test "Store json data" do
    changeset = Organization.changeset(%Organization{}, @valid_attrs)
    {:ok, org} = Bonsai.Repo.insert(changeset)
    assert @valid_attrs.info() == org.info
  end
end
</code></pre>