JLD.jl icon indicating copy to clipboard operation
JLD.jl copied to clipboard

"stored type does not match" error with "read" function but ok with "load" function

Open YongHee-Kim opened this issue 9 years ago • 0 comments
trafficstars

this might be related to issues/158

I'm currently working on simulation program and using JLD for logging. but while analysing log data, I found strange behavior with JLD. That same function "load" and "read" does not work as same function.

here is my example code

using JLD

type Item
    uid::UInt32
    id::Int32
    count::Int32
    let counter = UInt32(0)
        Item(id, count) =  new(counter += 1, id, count)
    end
end

# create dummy Data
items = Item[]
for i in 1:10, j in 1:5
    push!(items, Item(i, j))
end

jldopen("test.jld", "w") do file
    write(file, "log1", Dict(:date => DateTime(1,1,1), :item=>items))
end

for i in 1:10
    items[i].count += rand(1:100)
end

jldopen("test.jld", "r+") do file
    write(file, "log2", Dict(:date => DateTime(1,1,2), :item=>items))
end

This works fine

println(load("test.jld", "log1"))`
println(load("test.jld", "log2"))

But this does not work! pops up "stored type Base.Dates... does not match currently loaded type" error which is not even my custom type.

jldopen("test.jld", "r") do file
    println(read(file, "log1"))
    println(read(file, "log2"))
end

YongHee-Kim avatar May 26 '16 08:05 YongHee-Kim