varx/tech on Nostr: nprofile1q…rk39d I don't know if you recall our conversation a year or so ago about ...
nprofile1qy2hwumn8ghj7un9d3shjtnddaehgu3wwp6kyqpq8369m6ejyjfh47ths7qrlvqcu8jvyzxnuysx72cpvg95jfvt9l0sgrk39d (nprofile…k39d) I don't know if you recall our conversation a year or so ago about object mapping and serialization libraries, but I finally ended up cleaning up my janky custom serialization a bit, and thought you might find it interesting.
Here's a before/after of some of the code: https://codeberg.org/cavern/spelunk/commit/d374b320#diff-002831eefd5d25baa18f79aa8ce27f2dc862a523
Basically, instead of recursively passing values down through a chain of deserializer functions that just do `m["key"] as SomeType`, I keep the values wrapped in a type-aware context value that knows the descent path. The error messages are basically just as good as you'd get from a type-mapping library.
On a different branch I tried using kotlinx.serialization and honestly... this approach was less disruptive, more flexible, and took about the same number of lines of code! (And it potentially allows me to avoid a fundamental flaw of kotlinx.serialization, which is that it is currently incapable of detecting repeat keys in maps, which is a huge problem for signed/MAC'd data.)
Here's a before/after of some of the code: https://codeberg.org/cavern/spelunk/commit/d374b320#diff-002831eefd5d25baa18f79aa8ce27f2dc862a523
Basically, instead of recursively passing values down through a chain of deserializer functions that just do `m["key"] as SomeType`, I keep the values wrapped in a type-aware context value that knows the descent path. The error messages are basically just as good as you'd get from a type-mapping library.
On a different branch I tried using kotlinx.serialization and honestly... this approach was less disruptive, more flexible, and took about the same number of lines of code! (And it potentially allows me to avoid a fundamental flaw of kotlinx.serialization, which is that it is currently incapable of detecting repeat keys in maps, which is a huge problem for signed/MAC'd data.)