You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a better solution for this? I just had the `Jason.Encoder pipe to Poison, because I couldn't figure out how to get it to work otherwise. Here is my code:
lib/app_types.ex
Postgrex.Types.define(MyAppName.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason)
defimpl Jason.Encoder, for: [Geo.MultiPolygon] do
def encode(struct, opts) do
Geo.JSON.encode!(struct) |> Poison.encode!
end
end
defmodule MyAppName.Geo.Fence do
use Ecto.Schema
import Ecto.Changeset
@derive {Jason.Encoder, only: [:geom]}
schema "fences" do
field :friendly_name, :string
field :market_type, :string
field :name, :string
field :source_id, :string
field :state, :string
field :geoid, :string
field :code, :string
field :geom, Geo.PostGIS.Geometry
timestamps()
end
@doc false
def changeset(fence, attrs) do
fence
|> cast(attrs, [:name, :source_id, :market_type, :friendly_name, :state])
|> validate_required([:name])
end
end
The text was updated successfully, but these errors were encountered:
The idea was to not be tied to a specific encoder. But now that most things have settled on Jason (or at least the Poison interface) we can make the JSON module here actually return json.
The json_library configuration item currently is used for when Ecto.Type.cast is used to turn the field into one of the geo structs if the field is a geojson string.
Ah! @josevalim, looks like this was solved in the geo package by #141 and made optional in #149. Taking version 3.3.6 or newer of Geo will resolve it. 😄
Is there a better solution for this? I just had the `Jason.Encoder pipe to Poison, because I couldn't figure out how to get it to work otherwise. Here is my code:
lib/app_types.ex
config/config.exs
config/dev.exs
lib/my_app_name/geo/fence.ex
The text was updated successfully, but these errors were encountered: