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

Define #as_json for selective serialisation #154

Open
4 tasks
tassja opened this issue Feb 14, 2022 · 4 comments
Open
4 tasks

Define #as_json for selective serialisation #154

tassja opened this issue Feb 14, 2022 · 4 comments
Labels
product: placeos Issue relates to PlaceOS Product type: enhancement new feature or request

Comments

@tassja
Copy link
Contributor

tassja commented Feb 14, 2022

Implement #as_json or expand Clear JSON Deserialise model to accept annotation as macro arg in

examples

defining to_json(json : JSON::Builder) would be the best way to go instead of to_h/as_json

It might be helpful to get some ideas from how active-model does it.
https://github.com/spider-gazelle/active-model/blob/master/src/active-model/model.cr#L62-L84

Originally posted by @caspiano in #80 (comment)

@tassja tassja added the type: enhancement new feature or request label Feb 14, 2022
@jeremyw24 jeremyw24 added the product: placeos Issue relates to PlaceOS Product label Feb 22, 2022
@jeremyw24 jeremyw24 assigned grkek and unassigned tassja and grkek Apr 5, 2022
@caspiano
Copy link
Contributor

caspiano commented May 3, 2022

@chillfox What method are you using for your serialisation subsets in PortalAPI?

@chillfox
Copy link
Contributor

chillfox commented May 3, 2022

pretty much all of the controllers return json like this render :created, json: domain, type: ::PlaceOS::Portal::Models::Domain. If the returned object is a Clear model then the json method will be whatever Clear does, else there are some objects that use include JSON::Serializable for json.

@caspiano
Copy link
Contributor

caspiano commented May 3, 2022

Ahh, I was looking at this - https://github.com/place-technology/portal-api/blob/develop/src/models/user.cr#L9

I think having a macro to generate types like this would be nice (and methods on the model to generate the serialisation intermediate)

@chillfox
Copy link
Contributor

chillfox commented May 4, 2022

oh, yeah, there is that as well.
yep, some helper macros would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: placeos Issue relates to PlaceOS Product type: enhancement new feature or request
Projects
None yet
Development

No branches or pull requests

5 participants