After a good nights sleep, I discovered that the solution is really simple:
module Abc
export Ab, JLDExt
struct Ab
a
end
function set_jldext(m)
global JLDExt = m
@info "JLDExt set to '$JLDExt'"
end
end # module Abc
module JLDExt
using Abc, JLD
import JLD.writeas
import JLD.readas
struct JLDAb
a
end
JLD.writeas(x::Ab) = writeas(JLDAb(x.a))
JLD.readas(x::JLDAb) = Ab(x.a)
function __init__()
Abc.set_jldext(JLDExt)
@info "Loaded JLDExt"
end
end
using Test, Abc, JLD
@testset "JLD" begin
x = Ab(1)
fname = "/tmp/JLD_test.jld"
save(fname, "x", x)
@test load(fname)["x"] == x
end
Full code available at GitHub - GHTaarn/Abc.jl at good_fix