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

[Updated] formatting for nested attributes #302

Merged
merged 3 commits into from Dec 16, 2018
Merged

[Updated] formatting for nested attributes #302

merged 3 commits into from Dec 16, 2018

Conversation

broodfusion
Copy link
Contributor

Hi @beerlington, I submitted a new PR here.
Continuation from #295

@broodfusion
Copy link
Contributor Author

broodfusion commented Dec 14, 2018

FYI, could probably add this in the readme file:

To serialize nested attributes in a Phoenix app, include this anywhere:

defimpl JaSerializer.Formatter,
  for: [JaSerializer.Builder.Attribute] do
  alias JaSerializer.Formatter.Utils

  def format(%{value: value, key: key}) when is_map(value) or is_list(value) do
    values = Utils.deep_format_keys(value)
    {Utils.format_key(key), JaSerializer.Formatter.format(values)}
  end

  def format(attr) do
    {Utils.format_key(attr.key), JaSerializer.Formatter.format(attr.value)}
  end
end

Couldn't have this in attribute.ex because it would break the tests in attributes_test.ex for "allows overriding for struct formatting" and "map formatter can be changed".

Thanks!

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.

None yet

2 participants