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

Question about JSON::Serializable #190

taylorfinnell opened this Issue Dec 2, 2018 · 3 comments


3 participants

taylorfinnell commented Dec 2, 2018

When I use this in a model I end up with stuff like:

game_id_changed": false,
        "text_changed": false,
        "eliminated_changed": false,
        "advancing_changed": false,
        "category_changed": false,
        "question_number_changed": false,
        "question_count_changed": false,

Is there a way for Jennifer to exclude its internals from this automatically?



This comment has been minimized.


imdrasil commented Dec 3, 2018

Hm, ATM out of the box the only way how to deal with this is use instance.to_h.to_json. ATM Jennifer has no specialized tools for JSON serializing (or integration with any serializing mechanism. If this doesn't help you - I will think out some more clear solution

@imdrasil imdrasil added the question label Dec 3, 2018

@imdrasil imdrasil self-assigned this Dec 3, 2018


This comment has been minimized.


z64 commented Dec 3, 2018

@imdrasil You should only need to generate @[JSON::Field(ignore: true)] in mapping

require "json"

class Base
  macro mapping(*values)
    {% for value in values %}
      @[JSON::Field(ignore: true)]
      @{{value}}_id_changed : Bool = false
    {% end %}

class Model < Base
  include JSON::Serializable

  mapping(foo, bar, baz)

p # "{}"


This comment has been minimized.


imdrasil commented Dec 3, 2018

@z64 Nice catch, I'll add this as a temporary solution - I'm thinking about adding built-in #to_json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment