Using JsvSerializer to create "saved search" links

We have a number of UI search operations that submit a custom “search DTO” containing query criteria. This DTO may be a complex object with child objects, collections, etc. and thus we would like to use JsvSerializer to serialize an incoming DTO server-side to produce a querystring that can then be used to save the user’s search as a link. Since the UI is Angular we would need to be able to accept the incoming querystring from a “saved search” in the Angular ActivatedRoute and then parse the JSV into the Typescript representation of the search DTO so it can be submitted to the back-end search API to load the results associated with the saved search.

I have seen the JSV.js library but, per this post, it does not appear to be actively supported or recommended. Is there another way to achieve the result we are looking for above? Ideally, this would be a function that can convert JSV directly to a TS object representation of the DTO, but any solution ideas would be appreciated.

Where doing something similar in Instant Client Apps (apps.servicestack.net) where the entire request is captured in a URL.

It uses JSV impl in @servicestack/client to serialize a JS object to JSV, e.g:

let jsv = JSV.stringify(obj);

If you’re using any of the SPA project templates @servicestack/client is already imported.

Otherwise @servicestack/client is embedded inside ServiceStack.dll which you can access with:

<script src="/js/servicestack-client.js"></script>

For older or non ServiceStack apps you can resolve it from unpkg CDN instead:

<script src="https://unpkg.com/@servicestack/client/dist/servicestack-client.min.js"></script>

Which you can import into the global namespace with:

<script>
    var exports = { __esModule:true }, module = { exports:exports }
    function require(name) { return exports[name] || window[name] }
</script>
<script src="/js/servicestack-client.js"></script>
<script>
    Object.assign(window, exports); //import
    let jsv = JSV.stringify(obj);
</script>

This looks great. Thank you for the suggestion, Demis! As always, your speed in replying is super-human.

1 Like