From ef226b8a6a85943951ef492465e3e703e879b117 Mon Sep 17 00:00:00 2001 From: Ilya Shumeyko Date: Mon, 7 Sep 2020 23:57:15 +0300 Subject: [PATCH] Replace Poison with Jason for JSON encoding and decoding --- CHANGELOG.md | 5 ++++ README.md | 8 +++--- lib/geo.ex | 31 +++++++++++++++++--- lib/geo/json.ex | 18 ++++++------ mix.exs | 4 +-- mix.lock | 36 ++++++++++++------------ test/geo/json_test.exs | 64 ++++++++++++++++++++++-------------------- 7 files changed, 99 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d912cf5..7cbc4fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v3.3.6 + +- Enhancement + - [Replace Poison with Jason for JSON encoding in tests] + ## v3.3.5 - Fixed diff --git a/README.md b/README.md index 7e2016a..b7eabac 100644 --- a/README.md +++ b/README.md @@ -70,14 +70,14 @@ Geo only encodes and decodes maps shaped as GeoJSON. JSON encoding and decoding be done before and after. ```elixir -#Examples using Poison as the JSON parser +#Examples using Jason as the JSON parser iex(1)> Geo.JSON.encode(point) {:ok, %{ "type" => "Point", "coordinates" => [100.0, 0.0] }} -iex(2)> point = Poison.decode!("{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }") |> Geo.JSON.decode +iex(2)> point = Jason.decode!("{\"type\": \"Point\", \"coordinates\": [100.0, 0.0] }") |> Geo.JSON.decode %Geo.Point{ coordinates: {100.0, 0.0}, srid: nil } -iex(3)> Geo.JSON.encode!(point) |> Poison.encode! -"{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}" +iex(3)> Geo.JSON.encode!(point) |> Jason.encode! +"{\"coordinates\":[100.0,0.0],\"type\":\"Point\"}" ``` diff --git a/lib/geo.ex b/lib/geo.ex index a64ae1b..c7d71e4 100644 --- a/lib/geo.ex +++ b/lib/geo.ex @@ -55,15 +55,15 @@ defmodule Geo do be done before and after. ```elixir - #Examples using Poison as the JSON parser + #Examples using Jason as the JSON parser iex(1)> Geo.JSON.encode(point) %{ "type" => "Point", "coordinates" => [100.0, 0.0] } - iex(2)> point = Poison.decode!("{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }") |> Geo.JSON.decode + iex(2)> point = Jason.decode!("{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }") |> Geo.JSON.decode %Geo.Point{ coordinates: {100.0, 0.0}, srid: nil } - iex(3)> Geo.JSON.encode(point) |> Poison.encode! + iex(3)> Geo.JSON.encode(point) |> Jason.encode! "{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}" ``` """ @@ -87,7 +87,7 @@ defmodule Geo do @typedoc """ Endianess (byte-order) of the WKB/EWKB representation. - + * `:ndr` - little-endian * `:xdr` - big-endian @@ -118,4 +118,27 @@ defmodule Geo do end end end + + defimpl Jason.Encoder, + for: [ + Geo.Point, + Geo.PointZ, + Geo.PointM, + Geo.PointZM, + Geo.LineString, + Geo.LineStringZ, + Geo.Polygon, + Geo.PolygonZ, + Geo.MultiPoint, + Geo.MultiPointZ, + Geo.MultiLineString, + Geo.MultiLineStringZ, + Geo.MultiPolygon, + Geo.MultiPolygonZ, + Geo.GeometryCollection + ] do + def encode(value, opts) do + Jason.Encode.map(Geo.JSON.encode!(value), opts) + end + end end diff --git a/lib/geo/json.ex b/lib/geo/json.ex index 5ffa27a..30d71ac 100644 --- a/lib/geo/json.ex +++ b/lib/geo/json.ex @@ -11,17 +11,19 @@ defmodule Geo.JSON do in larger JSON structures. ``` - #Using Poison as the JSON parser for these examples + # Using Jason as the JSON parser for these examples - json = "{ \\"type\\": \\"Point\\", \\"coordinates\\": [100.0, 0.0] }" - geom = Poison.decode!(json) |> Geo.JSON.decode! - Geo.Point[coordinates: {100.0, 0.0}, srid: nil] + iex>json = "{ \\"type\\": \\"Point\\", \\"coordinates\\": [100.0, 0.0] }" + ...>json |> Jason.decode!() |> Geo.JSON.decode!() + %Geo.Point{coordinates: {100.0, 0.0}, srid: nil} - Geo.JSON.encode!(geom) |> Poison.encode! - "{ \\"type\\": \\"Point\\", \\"coordinates\\": [100.0, 0.0] }" + iex>geom = %Geo.Point{coordinates: {100.0, 0.0}, srid: nil} + ...>Jason.encode!(geom) + "{\\"coordinates\\":[100.0,0.0],\\"type\\":\\"Point\\"}" - Geo.JSON.encode!(geom) - %{ "type" => "Point", "coordinates" => [100.0, 0.0] } + iex>geom = %Geo.Point{coordinates: {100.0, 0.0}, srid: nil} + ...>Geo.JSON.encode!(geom) + %{"type" => "Point", "coordinates" => [100.0, 0.0]} ``` """ diff --git a/mix.exs b/mix.exs index ce291e6..3ba9a20 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Geo.Mixfile do def project do [ app: :geo, - version: "3.3.5", + version: "3.3.6", elixir: "~> 1.6", deps: deps(), description: description(), @@ -36,7 +36,7 @@ defmodule Geo.Mixfile do defp deps do [ - {:poison, "~> 4.0", only: :test}, + {:jason, "~> 1.2", only: :test}, {:ex_doc, "~> 0.18", only: :dev}, {:excoveralls, "~> 0.12.1", only: :test}, {:stream_data, "~> 0.4.3", only: :test}, diff --git a/mix.lock b/mix.lock index 9c22bb4..49fa57e 100644 --- a/mix.lock +++ b/mix.lock @@ -1,29 +1,29 @@ %{ - "benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"}, - "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, + "benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm", "3ad58ae787e9c7c94dd7ceda3b587ec2c64604563e049b2a0e8baafae832addb"}, + "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.0", "b2b88db6d7d12f99997b584d09fad98e560b817a20dab6a526830e339f54cdb3", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, - "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"}, - "earmark": {:hex, :earmark, "1.3.5", "0db71c8290b5bc81cb0101a2a507a76dca659513984d683119ee722828b424f6", [:mix], [], "hexpm"}, + "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, + "earmark": {:hex, :earmark, "1.3.5", "0db71c8290b5bc81cb0101a2a507a76dca659513984d683119ee722828b424f6", [:mix], [], "hexpm", "762b999fd414fb41e297944228aa1de2cd4a3876a07f968c8b11d1e9a2190d07"}, "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, - "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"}, - "excoveralls": {:hex, :excoveralls, "0.12.1", "a553c59f6850d0aff3770e4729515762ba7c8e41eedde03208182a8dc9d0ce07", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f1155337ae17ff7a1255217b4c1ceefcd1860b7ceb1a1874031e7a861b052e39"}, + "excoveralls": {:hex, :excoveralls, "0.12.1", "a553c59f6850d0aff3770e4729515762ba7c8e41eedde03208182a8dc9d0ce07", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "5c1f717066a299b1b732249e736c5da96bb4120d1e55dc2e6f442d251e18a812"}, "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, - "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, - "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, + "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, + "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"}, + "jason": {:hex, :jason, "1.2.1", "12b22825e22f468c02eb3e4b9985f3d0cb8dc40b9bd704730efa11abd2708c44", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b659b8571deedf60f79c5a608e15414085fa141344e2716fbd6988a084b5f993"}, "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"}, - "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"}, - "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"}, - "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"}, - "nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, + "makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a10c6eb62cca416019663129699769f0c2ccf39428b3bb3c0cb38c718a0c186d"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "d4b316c7222a85bbaa2fd7c6e90e37e953257ad196dc229505137c5e505e9eff"}, + "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, + "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, + "nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm", "00e3ebdc821fb3a36957320d49e8f4bfa310d73ea31c90e5f925dc75e030da8f"}, + "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, "postgrex": {:hex, :postgrex, "0.13.0", "e101ab47d0725955c5c8830ae8812412992e02e4bd9db09e17abb0a5d82d09c7", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"}, - "stream_data": {:hex, :stream_data, "0.4.3", "62aafd870caff0849a5057a7ec270fad0eb86889f4d433b937d996de99e3db25", [:mix], [], "hexpm"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"}, + "stream_data": {:hex, :stream_data, "0.4.3", "62aafd870caff0849a5057a7ec270fad0eb86889f4d433b937d996de99e3db25", [:mix], [], "hexpm", "7dafd5a801f0bc897f74fcd414651632b77ca367a7ae4568778191fc3bf3a19a"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, } diff --git a/test/geo/json_test.exs b/test/geo/json_test.exs index 5be43ec..7f23241 100644 --- a/test/geo/json_test.exs +++ b/test/geo/json_test.exs @@ -2,6 +2,8 @@ defmodule Geo.JSON.Test do use ExUnit.Case, async: true use ExUnitProperties + doctest Geo.JSON + test "Point to GeoJson Map" do geom = %Geo.Point{coordinates: {100.0, 0.0}} json = Geo.JSON.encode!(geom) @@ -11,9 +13,9 @@ defmodule Geo.JSON.Test do test "Point to GeoJson" do geom = %Geo.Point{coordinates: {100.0, 0.0}} - json = Geo.JSON.encode!(geom) |> Poison.encode!() + json = Geo.JSON.encode!(geom) |> Jason.encode!() - assert(json == "{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}") + assert(json == "{\"coordinates\":[100.0,0.0],\"type\":\"Point\"}") end test "PointZ to GeoJson Map" do @@ -25,29 +27,29 @@ defmodule Geo.JSON.Test do test "PointZ to GeoJson" do geom = %Geo.PointZ{coordinates: {100.0, 0.0, 70.0}} - json = Geo.JSON.encode!(geom) |> Poison.encode!() + json = Geo.JSON.encode!(geom) |> Jason.encode!() - assert(json == "{\"type\":\"Point\",\"coordinates\":[100.0,0.0,70.0]}") + assert(json == "{\"coordinates\":[100.0,0.0,70.0],\"type\":\"Point\"}") end test "PointZ from GeoJson" do json = "{\"type\":\"Point\",\"coordinates\":[100.0,0.0,70.0]}" - geom = Poison.decode!(json) |> Geo.JSON.decode!() + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom == %Geo.PointZ{coordinates: {100.0, 0.0, 70.0}}) end test "LineString to GeoJson" do geom = %Geo.LineString{coordinates: [{100.0, 0.0}, {101.0, 1.0}]} - json = Geo.JSON.encode!(geom) |> Poison.encode!() + json = Geo.JSON.encode!(geom) |> Jason.encode!() - assert(json == "{\"type\":\"LineString\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}") + assert(json == "{\"coordinates\":[[100.0,0.0],[101.0,1.0]],\"type\":\"LineString\"}") end test "GeoJson to Point and back" do json = "{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom.coordinates == {100.0, 0.0}) @@ -59,8 +61,8 @@ defmodule Geo.JSON.Test do json = "{\"type\":\"Point\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"EPSG:4326\"}},\"coordinates\":[100.0, 101.0]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom.coordinates == {100.0, 101.0}) assert(geom.srid == 4326) @@ -71,8 +73,8 @@ defmodule Geo.JSON.Test do test "GeoJson to LineString and back" do json = "{ \"type\": \"LineString\", \"coordinates\": [ [100.0, 0.0], [101.0, 1.0] ]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom.coordinates == [{100.0, 0.0}, {101.0, 1.0}]) new_exjson = Geo.JSON.encode!(geom) @@ -83,7 +85,7 @@ defmodule Geo.JSON.Test do json = "{ \"type\": \"Polygon\", \"coordinates\": [[ [100.0, 0.0, 1.0], [101.0, 0.0, 1.0], [101.0, 1.0, 1.0], [100.0, 1.0, 1.0], [100.0, 0.0, 1.0] ]]}" - geom = Poison.decode!(json) |> Geo.JSON.decode!() + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert( geom.coordinates == [[{100.0, 0.0}, {101.0, 0.0}, {101.0, 1.0}, {100.0, 1.0}, {100.0, 0.0}]] @@ -94,8 +96,8 @@ defmodule Geo.JSON.Test do json = "{ \"type\": \"Polygon\", \"coordinates\": [[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert( geom.coordinates == [[{100.0, 0.0}, {101.0, 0.0}, {101.0, 1.0}, {100.0, 1.0}, {100.0, 0.0}]] @@ -107,8 +109,8 @@ defmodule Geo.JSON.Test do test "GeoJson to MultiPoint and back" do json = "{ \"type\": \"MultiPoint\", \"coordinates\": [ [100.0, 0.0], [101.0, 1.0] ]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom.coordinates == [{100.0, 0.0}, {101.0, 1.0}]) new_exjson = Geo.JSON.encode!(geom) @@ -119,8 +121,8 @@ defmodule Geo.JSON.Test do json = "{ \"type\": \"MultiLineString\", \"coordinates\": [[ [100.0, 0.0], [101.0, 1.0] ],[ [102.0, 2.0], [103.0, 3.0] ]]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(geom.coordinates == [[{100.0, 0.0}, {101.0, 1.0}], [{102.0, 2.0}, {103.0, 3.0}]]) new_exjson = Geo.JSON.encode!(geom) @@ -131,8 +133,8 @@ defmodule Geo.JSON.Test do json = "{ \"type\": \"MultiPolygon\", \"coordinates\": [[[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]],[[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]],[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]]]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert( geom.coordinates == [ @@ -152,8 +154,8 @@ defmodule Geo.JSON.Test do json = "{ \"type\": \"GeometryCollection\",\"geometries\": [{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0]},{ \"type\": \"LineString\",\"coordinates\": [ [101.0, 0.0], [102.0, 1.0] ]}]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(Enum.count(geom.geometries) == 2) @@ -189,8 +191,8 @@ defmodule Geo.JSON.Test do valid_json = "{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }" invalid_json = "{ \"type\": \"random_type\", \"coordinates\": [100.0, 0.0] }" - assert {:ok, _value} = Poison.decode!(valid_json) |> Geo.JSON.decode() - assert {:error, _error} = Poison.decode!(invalid_json) |> Geo.JSON.decode() + assert {:ok, _value} = Jason.decode!(valid_json) |> Geo.JSON.decode() + assert {:error, _error} = Jason.decode!(invalid_json) |> Geo.JSON.decode() end test "encode/1" do @@ -203,10 +205,10 @@ defmodule Geo.JSON.Test do test "Point with properties to GeoJson" do geom = %Geo.Point{coordinates: {100.0, 0.0}, properties: %{hi: "there"}} - json = Geo.JSON.encode!(geom) |> Poison.encode!() + json = Geo.JSON.encode!(geom) |> Jason.encode!() assert( - json == "{\"type\":\"Point\",\"properties\":{\"hi\":\"there\"},\"coordinates\":[100.0,0.0]}" + json == "{\"coordinates\":[100.0,0.0],\"properties\":{\"hi\":\"there\"},\"type\":\"Point\"}" ) end @@ -214,8 +216,8 @@ defmodule Geo.JSON.Test do json = "{\"properties\":{\"hi\":\"there\"}, \"type\": \"GeometryCollection\",\"geometries\": [{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0]},{ \"type\": \"LineString\",\"coordinates\": [ [101.0, 0.0], [102.0, 1.0] ]}]}" - exjson = Poison.decode!(json) - geom = Poison.decode!(json) |> Geo.JSON.decode!() + exjson = Jason.decode!(json) + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(Enum.count(geom.geometries) == 2) @@ -280,7 +282,7 @@ defmodule Geo.JSON.Test do } """ - geom = Poison.decode!(json) |> Geo.JSON.decode!() + geom = Jason.decode!(json) |> Geo.JSON.decode!() assert(Enum.count(geom.geometries) == 2)