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

Allow passing in annotation arg in macro column #7

Open
dukenguyenxyz opened this issue Jan 20, 2021 · 0 comments
Open

Allow passing in annotation arg in macro column #7

dukenguyenxyz opened this issue Jan 20, 2021 · 0 comments
Labels

Comments

@dukenguyenxyz
Copy link
Contributor

dukenguyenxyz commented Jan 20, 2021

Step 1. Update macro column to accept annotations arg, similar to this PR

macro column(name, primary = false, converter = nil, column_name = nil, presence = true, mass_assign = true, annotations = nil)

annotations should be in serialisation, they would be added on top of instance_vars responsible for serialisation/deserialisation. There are two case scenarios

Scenario (a) Keep using Clear::Model::JSONDeserialize

Add the annotations on top of assigner's instance_var

Scenario (b) Reimplement Clear::Model::JSONDeserialize

This module currently relies on implementing an intermediary Assigner class, and then re-assigning the individual props to the original class. This is slightly slower than deserialising directly into the original class. We can implement this first, and then apply the annotations on top of the instance_vars. Afterwards, we need to add @[JSON::Field(ignore: true)] for all irrelevant instance_vars. We would also need to declare json_deserialise keys as instance_vars instead of instance_vars_column which are the standard instance_vars name currently.

This is highly complicated, preferably implement (a) first, and then (b) since (a) is easier.

Step 2. Currently Clear has a built-in #to_json method, therefore there will be no effect of annotations on #to_json (only #from_json). To fix this, after implementing step 1, if we want to use the #to_json from the JSON::Serializable module in STDLIB in order to allow the annotations passed in to have effect on #to_json, we need to override this built-in #to_json method with the STDLIB method.

@dukenguyenxyz dukenguyenxyz self-assigned this Jan 20, 2021
@jeremyw24 jeremyw24 added the type: enhancement new feature or request label Apr 1, 2021
@dukenguyenxyz dukenguyenxyz changed the title Allow specifying JSON Field annotations Allow passing in annotation arg in macro column Jul 14, 2021
@dukenguyenxyz dukenguyenxyz removed their assignment Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants