If we want custom serialization for a type that I do not own, I currently need to wrap it in my own type to avoid type piracy for JLD2.writeas:
struct MyWrappedType
x::TypeIDontOwn
end
JLD2.writeas(::Type{MyWrappedType}) = ...
But this only works to a certain degree, if I want to serialize a Vector/Tuple/Pair/etc. that contains TypeIDontOwn, it becomes much harder.
One solution would be if it was possible to supply a "context" object to e.g. jldopen, that was passed along to the relevant functions. Then we could write
JLD2.writeas(::MyContext, ::Type{TypeIDontOwn} = ...`
thus avoiding piracy. (This strategy is used by e.g. StableHashTraits.jl.)
It would naturally fallback to calling without a context, so this is not a breaking change.
Is there any other way to achieve this currently?
If we want custom serialization for a type that I do not own, I currently need to wrap it in my own type to avoid type piracy for
JLD2.writeas:But this only works to a certain degree, if I want to serialize a
Vector/Tuple/Pair/etc. that containsTypeIDontOwn, it becomes much harder.One solution would be if it was possible to supply a "context" object to e.g.
jldopen, that was passed along to the relevant functions. Then we could writethus avoiding piracy. (This strategy is used by e.g. StableHashTraits.jl.)
It would naturally fallback to calling without a context, so this is not a breaking change.
Is there any other way to achieve this currently?