✅ Welp with making a function more abstract
I'm developing a website with server-side filtering. Users can save sets of filters, which are stored as JSON in a Filters table in the database. My challenge is that the filters can apply to different entities (e.g., Tasks, Bookings, Vehicles), so the input objects to the backend vary.
My problem is with the functions that save and retrieve these filters:
Saving: serialize the specific filter object to JSON and store it.
Loading: read the JSON from the DB and deserialize it into the correct class.
Since the only part where the code could change for saving/reading is the class used to deserialize and serialize, which could be the best approach to avoid code dup?
I thought about using a template function. In this case would it be better to have different endpoints to save/retrieve data or could i pass the type of filter to the backend?
8 Replies
Unknown User•5d ago
Message Not Public
Sign In & Join Server To View
(is it so complex that you need to save it in a json?)
Unknown User•5d ago
Message Not Public
Sign In & Join Server To View
ok so you would take it as an expression serialization that is interpreted by the grid/component itself
Unknown User•5d ago
Message Not Public
Sign In & Join Server To View
sure
Have you heard of
BinaryFormatter
?
Please don't use it, it's a joke Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
🤡