-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making it possible to use another JSON library than
jsx
We already use `jiffy` in our project to handle JSONs, which makes integrating `erlastic_search` a pain, since it uses `jsx`, which has a different way of representing JSONs in Erlang, for example: ``` 1> SimpleJson = <<"{\"key\":\"value\"}">>. <<"{\"key\":\"value\"}">> 2> jiffy:decode(SimpleJson). {[{<<"key">>,<<"value">>}]} 3> jsx:decode(SimpleJson). [{<<"key">>,<<"value">>}] ``` This patch makes it possible to use any JSON library, as long as it defines the two following callbacks: ```erlang -callback encode(json()) -> binary(). -callback decode(binary()) -> json(). ``` This setting is done at compile time, by defining an `ERLASTIC_SEARCH_JSON_MODULE` environment variable containing the name of the module containing the two callbacks above. Updated the specs to account for this change.
- Loading branch information
Showing
6 changed files
with
93 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ErlOpts = proplists:get_value(erl_opts, CONFIG), | ||
|
||
JsonModuleStr = case os:getenv("ERLASTIC_SEARCH_JSON_MODULE") of | ||
Value when erlang:is_list(Value), erlang:length(Value) > 0 -> | ||
Value; | ||
_ -> | ||
"jsx" | ||
end, | ||
|
||
JsonModule = erlang:list_to_atom(JsonModuleStr), | ||
|
||
NewErlOpts = [ {d, 'ERLASTIC_SEARCH_JSON_MODULE', JsonModule} | ErlOpts], | ||
lists:keystore(erl_opts, 1, CONFIG, {erl_opts, NewErlOpts}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters