Skip to content

Commit

Permalink
Merge 5350d33 into f5de8e1
Browse files Browse the repository at this point in the history
  • Loading branch information
Afoucaul committed Aug 8, 2018
2 parents f5de8e1 + 5350d33 commit e095a1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 9 additions & 1 deletion lib/poison/encoder.ex
Expand Up @@ -329,7 +329,7 @@ defimpl Poison.Encoder, for: List do
end
end

defimpl Poison.Encoder, for: [Range, Stream, MapSet, HashSet] do
defimpl Poison.Encoder, for: [Stream, MapSet, HashSet] do
alias Poison.Encoder

use Poison.Pretty
Expand Down Expand Up @@ -369,6 +369,14 @@ defimpl Poison.Encoder, for: [Date, Time, NaiveDateTime, DateTime] do
end
end

defimpl Poison.Encoder, for: Range do
alias Poison.Encoder

def encode(range, options) do
Encoder.Map.encode(%{first: range.first, last: range.last}, options)
end
end

defimpl Poison.Encoder, for: Any do
alias Poison.{Encoder, EncodeError}

Expand Down
25 changes: 16 additions & 9 deletions test/poison/encoder_test.exs
Expand Up @@ -79,15 +79,22 @@ defmodule Poison.EncoderTest do
end

test "Range" do
assert to_json(1..3) == "[1,2,3]"

assert to_json(1..3, pretty: true) == """
[
1,
2,
3
]\
"""
r1 = 1..10
assert to_json(r1, pretty: true) == """
{
"last": 10,
"first": 1
}\
"""

a = 1
b = 999999999
assert to_json(a..b, pretty: true) == """
{
"last": #{b},
"first": #{a}
}\
"""
end

test "Stream" do
Expand Down

0 comments on commit e095a1e

Please sign in to comment.