Something new in this regard, please? How to write a matrix correctly? Thx
If you structure is mutable, you can use reshape:
julia> mutable struct A
x
end
julia> using StructTypes
julia> StructTypes.StructType(::Type{A}) = StructTypes.Struct()
julia> using JSON3
julia> a = A(rand(3,3))
julia> s = JSON3.write(a)
julia> sread = JSON3.read(s,A)
julia> sread.x = reshape(sread.x,3,3)
3×3 Array{Any,2}:
0.89818 0.503697 0.0568256
0.424703 0.505502 0.570105
0.385958 0.721714 0.46072
If the structure is not mutable, then what I do is to reshape the vectors read saving them in new arrays, and then I initialize a new structure with the data reshaped.
Thanks @leandromartinez98 for the tips, but I’d rather adjust the structure attribute of Matrix to Vector (structure is immutable).
Now I have a question how to write/read Dates.Period
?
mutable struct Foo
samplingPeriod::Period
end
JSON3.StructType(::Type{<:Foo}) = JSON3.Struct()
JSON3.StructType(::Type{<:Period}) = JSON3.StringType()
str = JSON3.write(Foo(Second(3600)))
"{\"samplingPeriod\":\"3600 seconds\"}"
o = JSON3.read(str, Foo)
ERROR: MethodError: no method matching Period(::String)
Do I have to overload the Period
method or is there a more elegant way? Any experience? Thanks.
I am having an issue when serializing If someone can help on this regards: