ex_twilio
ex_twilio copied to clipboard
0.9.0 changes the behavior for nested data
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
+1 to this, this just bit me too