diff --git a/lib/poison/encoder.ex b/lib/poison/encoder.ex index 2eefc45b..ef15d4e3 100644 --- a/lib/poison/encoder.ex +++ b/lib/poison/encoder.ex @@ -74,6 +74,11 @@ defimpl Poison.Encoder, for: Atom do def encode(true, _), do: "true" def encode(false, _), do: "false" + def encode(atom, %{force: mapping} = options) do + value = Map.get(mapping, atom, Atom.to_string(atom)) + Poison.Encoder.encode(value, Map.delete(options, :force)) + end + def encode(atom, options) do Poison.Encoder.BitString.encode(Atom.to_string(atom), options) end diff --git a/test/poison/encoder_test.exs b/test/poison/encoder_test.exs index c28d1c61..158c1fb2 100644 --- a/test/poison/encoder_test.exs +++ b/test/poison/encoder_test.exs @@ -8,6 +8,8 @@ defmodule Poison.EncoderTest do assert to_json(true) == "true" assert to_json(false) == "false" assert to_json(:poison) == ~s("poison") + assert to_json(:null) == ~s("null") + assert to_json(:null, force: %{null: nil}) == "null" end test "Integer" do