# BSON: Loading package artifacts that are typed by package itself

**URL:** <https://discourse.julialang.org/t/bson-loading-package-artifacts-that-are-typed-by-package-itself/84791>\
**Category:** Package Management\
**Tags:** question, bson, artifacts\
**Created:** [July 26, 2022, 5:25am UTC](https://discourse.julialang.org/t/bson-loading-package-artifacts-that-are-typed-by-package-itself/84791 "2022-07-26T05:25:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pat-alt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pat-alt/32/34264_2.png) [@pat-alt](https://discourse.julialang.org/u/pat-alt)\
**Post date:** [July 26, 2022, 5:25am UTC](https://discourse.julialang.org/t/bson-loading-package-artifacts-that-are-typed-by-package-itself/84791/1 "2022-07-26T05:25:32Z")

</div>

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

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 👍

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 26, 2022, 6:40am UTC](https://discourse.julialang.org/t/bson-loading-package-artifacts-that-are-typed-by-package-itself/84791/2 "2022-07-26T06:40:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pat-alt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pat-alt/32/34264_2.png) [@pat-alt](https://discourse.julialang.org/u/pat-alt)\
**Post date:** [July 26, 2022, 6:47am UTC](https://discourse.julialang.org/t/bson-loading-package-artifacts-that-are-typed-by-package-itself/84791/3 "2022-07-26T06:47:56Z")

</div>

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