sile / jsone

Erlang JSON library
MIT License
291 stars 72 forks source link

Add `jsone:term_to_json_string/1` as the default value of `map_unknown_value` option. #65

Closed sile closed 3 years ago

sile commented 3 years ago

This PR makes it possible to encode all Erlang terms by default.

% Before: Cannot encode PID.
> {error, _} = jsone:try_encode(self()).

% After: PID (and other Erlang terms that aren't natively supported by `jsone`) are
%        encoded using the result of `io_lib:format("~p", [...]])`.
> jsone:try_encode(self()).
{ok,<<"\"<0.198.0>\"">>}

If you prefer the previous behavior, you need to specify {map_unknown_value, undefined} explicitly.

Resolves #64

codecov-commenter commented 3 years ago

Codecov Report

Merging #65 (7662c42) into master (f34edbc) will increase coverage by 0.03%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   90.41%   90.44%   +0.03%     
==========================================
  Files           3        3              
  Lines         292      293       +1     
==========================================
+ Hits          264      265       +1     
  Misses         28       28              
Impacted Files Coverage Δ
src/jsone_encode.erl 86.45% <ø> (ø)
src/jsone.erl 66.66% <100.00%> (+2.38%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f34edbc...7662c42. Read the comment docs.

sile commented 3 years ago

Please let me know if there is someone who doesn't want the change of the map_unknown_value default value. I'll merge this PR a week after if there is no such comment.