BSON: Loading package artifacts that are typed by package itself

… struggling to even phrase that title properly, so I’m probably doing something silly :frowning:

I’m relying on BSON to store some objects created and typed by my own package MyPkg as artifacts: BSON.@save path some_object where typeof(some_object) <: MyPkg.SomeType. To allow users of MyPkg to load the artifact, I’m then providing a simple function MyPkg.load_some_object which essentially just uses BSON again to load the object.

The problem I’m facing is that since typeof(some_object) <: MyPkg.SomeType, BSON complains that is needs MyPkg to read the file. Things actually work out when I call using MyPkg inside the package source code before load_some_object, but this just smells like trouble (I guess?).

Any thoughts/advice would be much appreciated :+1:

It’s cute that you can serialize custom types but my experience is that in the long run you’re better off only saving basic types and have load/save functions which interface the data to your types.

1 Like

OK, I was afraid that might be the best option. Thanks!