danielberkompas / ex_twilio

Twilio API client for Elixir
MIT License
334 stars 146 forks source link

0.9.0 changes the behavior for nested data #148

Open al2o3cr opened 3 years ago

al2o3cr commented 3 years ago

Before 0.9.0, a response like ExTwilio.Lookup.PhoneNumber had string keys in child maps like carrier, because Poison doesn't convert them to atoms:

iex> resp_str = "{\"add_ons\":null,\"caller_name\":null,\"carrier\":{\"name\":\"foo\",\"type\":\"bar\"},\"country_code\":\"US\",\"national_format\":\"blergh\",\"phone_number\":\"1234\",\"url\":\"abcd\"}"

iex> Poison.decode!(resp_str, as: ExTwilio.Lookup.PhoneNumber.__struct__)
%ExTwilio.Lookup.PhoneNumber{
  add_ons: nil,
  caller_name: nil,
  carrier: %{"name" => "foo", "type" => "bar"},
  country_code: "US",
  national_format: "blergh",
  phone_number: "1234",
  url: "abcd"
}

but the corresponding Jason code does:

iex> struct(ExTwilio.Lookup.PhoneNumber, Jason.decode!(resp_str, keys: :atoms))
%ExTwilio.Lookup.PhoneNumber{
  add_ons: nil,
  caller_name: nil,
  carrier: %{name: "foo", type: "bar"},
  country_code: "US",
  national_format: "blergh",
  phone_number: "1234",
  url: "abcd"
}

This should be called out in the changelog.

EDIT: removed unroutable private IP address from the example

srcrip commented 1 year ago

+1 to this, this just bit me too