Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conditional map support for mochijson2:encode/2 #184

Merged
merged 1 commit into from
Dec 19, 2016

Conversation

marjaimate
Copy link
Contributor

  • Platform define map_available added to allow conditional support for maps
  • Expand the encode/2 functionality to parse maps
  • Added json_encode_map/2 to handle map parsing, similar to arrays and proplists
  • Unit tests for map encoding

@@ -149,6 +149,43 @@ parse_decoder_options([{format, Format} | Rest], State)
when Format =:= struct orelse Format =:= eep18 orelse Format =:= proplist ->
parse_decoder_options(Rest, State#decoder{object_hook=Format}).


-ifdef(map_available).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be ideal to put this ifdef in the existing json_encode/2 function rather than having entirely separate versions of this function.

Copy link
Contributor Author

@marjaimate marjaimate Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etrepum I thought you can't use macros in function head(s), so this was the solution I come up with, albeit not the prettiest one.

I tried the following:

-ifdef(map_avaliable).
json_encode(M, State) when is_map(M) ->
    json_encode_map(M, State);
-endif.
json_encode(...) ->
    ...

This is giving out to me when compiling on 18.3.

etrepum added a commit that referenced this pull request Dec 19, 2016
etrepum added a commit that referenced this pull request Dec 19, 2016
etrepum added a commit that referenced this pull request Dec 19, 2016
@etrepum etrepum merged commit 5d4660d into mochi:master Dec 19, 2016
@etrepum
Copy link
Member

etrepum commented Dec 19, 2016

This is now available in the tagged v2.16.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants