serializations that support generics?

91 views
Skip to first unread message

Jason E. Aten

unread,
Feb 26, 2025, 2:31:16 PM2/26/25
to golang-nuts
Are there serialization formats that support Go generics?

I'd like to take a look at how they do it, if they exist.

I'm wondering: Do they use reflection at runtime?

and/or: Do they parse the source looking for template instantiations at go:generate time
to codegen for all possible instantiations?

I've added some generics support to my serialization package, greenpack (https://github.com/glycerine/greenpack), and I'm curious what approaches exist.
I used to just skip generic structs, but now I serialize them and just skip the
fields that contain type parameters; there are pre/post load hooks that can
be used to manually add reflection code, if desired.

I'm thinking that (for automatic support) reflection at runtime for any generic fields is probably the only sane way to go; but I'd be glad to be aware of other possible approaches.

At the moment I parse the source code at go:generate time and look for instantiations of generics; using the first found instantiation to generate the automatic test code.

Thanks for any ideas.

Jason
Reply all
Reply to author
Forward
0 new messages