Skip to content

How to serialise ActiveRecord model (or any data, really) using JSI gem? #290

Answered by notEthan
makemp asked this question in Q&A
Discussion options

You must be logged in to vote

It looks like you mean to limit the serialization of a record. JSICoder is for serialization between database columns (of either stringified or native JSON) and record attributes - it doesn't do anything with whole records.

JSI can filter instances based on schemas describing them, which I'll demonstrate below - but it needs JSON compatible types to instantiate. You can get that from AR's builtin serialization, or other gems, but that's outside JSI's scope.

From there, JSI has methods to select a document's nodes: jsi_select_descendents_leaf_first and node_first. These can select based on what schemas (or lack thereof) describe a given node. Some examples follow, and I put a full standalo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@makemp
Comment options

Answer selected by makemp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants