Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/jose_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ check_json(_Fallback, Entries) ->
undefined ->
case code:ensure_loaded(elixir) of
{module, elixir} ->
check_json_modules([json, ojson, 'Elixir.Jason', 'Elixir.Poison', jiffy, jsone, jsx, thoas]);
check_json_modules(['Elixir.JSON', json, ojson, 'Elixir.Jason', 'Elixir.Poison', jiffy, jsone, jsx, thoas]);
_ ->
check_json_modules([json, ojson, jiffy, jsone, jsx, thoas])
end;
Expand All @@ -481,6 +481,8 @@ check_json_module(ojson) ->
jose_json_ojson;
check_json_module(thoas) ->
jose_json_thoas;
check_json_module('Elixir.JSON') ->
jose_json_elixir;
check_json_module('Elixir.Jason') ->
jose_json_jason;
check_json_module('Elixir.Poison') ->
Expand Down
21 changes: 21 additions & 0 deletions src/json/jose_json_elixir.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%% -*- mode: erlang; tab-width: 4; indent-tabs-mode: 1; st-rulers: [70] -*-
%% vim: ts=4 sw=4 ft=erlang noet
-module(jose_json_elixir).

-behaviour(jose_json).

%% jose_json callbacks
-export([decode/1]).
-export([encode/1]).

%%====================================================================
%% jose_json callbacks
%%====================================================================

-spec decode(binary()) -> dynamic().
decode(Binary) ->
'Elixir.JSON':'decode!'(Binary).

-spec encode(dynamic()) -> binary().
encode(Term) ->
'Elixir.JSON':'encode!'(Term).
33 changes: 33 additions & 0 deletions test/jose_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ defmodule JOSETest do
assert binary == :erlang.element(2, JOSE.JWE.to_binary(jwe))
assert jwe == JOSE.JWE.from_binary(binary)
assert jwe == JOSE.JWE.from(jwe)
# JSON
JOSE.json_module(JSON)
assert :jose_json_elixir == JOSE.json_module()
assert map == :erlang.element(2, JOSE.JWE.to_map(jwe))
assert binary == :erlang.element(2, JOSE.JWE.to_binary(jwe))
assert jwe == JOSE.JWE.from_binary(binary)
assert jwe == JOSE.JWE.from(jwe)
# Poison
JOSE.json_module(Poison)

Expand Down Expand Up @@ -260,6 +267,17 @@ defmodule JOSETest do
assert jwk == :erlang.element(2, JOSE.JWK.from_binary(password, JOSE.JWK.to_binary(password, jwk)))
assert jwk == :erlang.element(2, JOSE.JWK.from_map(password, JOSE.JWK.to_map(password, jwk)))
assert jwk == JOSE.JWK.from_pem(password, JOSE.JWK.to_pem(password, jwk))
# JSON
JOSE.json_module(JSON)
assert :jose_json_elixir == JOSE.json_module()
assert map == :erlang.element(2, JOSE.JWK.to_map(jwk))
assert binary == :erlang.element(2, JOSE.JWK.to_binary(jwk))
assert jwk == JOSE.JWK.from_binary(binary)
assert jwk == JOSE.JWK.from(jwk)
assert jwk == JOSE.JWK.from_pem(JOSE.JWK.to_pem(jwk))
assert jwk == :erlang.element(2, JOSE.JWK.from_binary(password, JOSE.JWK.to_binary(password, jwk)))
assert jwk == :erlang.element(2, JOSE.JWK.from_map(password, JOSE.JWK.to_map(password, jwk)))
assert jwk == JOSE.JWK.from_pem(password, JOSE.JWK.to_pem(password, jwk))
# Poison
JOSE.json_module(Poison)

Expand Down Expand Up @@ -348,6 +366,14 @@ defmodule JOSETest do
assert binary == :erlang.element(2, JOSE.JWS.to_binary(jws))
assert jws == JOSE.JWS.from_binary(binary)
assert jws == JOSE.JWS.from(jws)
# JSON
JOSE.json_module(JSON)
assert :jose_json_elixir == JOSE.json_module()
assert map == :erlang.element(2, JOSE.JWS.to_map(jws))
assert binary == :erlang.element(2, JOSE.JWS.to_binary(jws))
assert jws == JOSE.JWS.from_binary(binary)
assert jws == JOSE.JWS.from(jws)

# Poison
JOSE.json_module(Poison)

Expand Down Expand Up @@ -413,6 +439,13 @@ defmodule JOSETest do
assert binary == :erlang.element(2, JOSE.JWT.to_binary(jwt))
assert jwt == JOSE.JWT.from_binary(binary)
assert jwt == JOSE.JWT.from(jwt)
# JSON
JOSE.json_module(JSON)
assert :jose_json_elixir == JOSE.json_module()
assert map == :erlang.element(2, JOSE.JWT.to_map(jwt))
assert binary == :erlang.element(2, JOSE.JWT.to_binary(jwt))
assert jwt == JOSE.JWT.from_binary(binary)
assert jwt == JOSE.JWT.from(jwt)
# Poison
JOSE.json_module(Poison)

Expand Down