bhftbootcamp / Serde.jl

Serde is a Julia library for (de)serializing data to/from various formats. The library offers a simple and concise API for defining custom (de)serialization behavior for user-defined types
Apache License 2.0
31 stars 7 forks source link

Deserialize CSV to nested composite types #48

Open NeroBlackstone opened 2 months ago

NeroBlackstone commented 2 months ago

Currently, nested data cannot be deserialized correctly:

julia> struct NestedData
           id::Int
           name::String
       end

julia> struct Data
           id::Int
           nest::NestedData
       end

julia> data = [Data(1,NestedData(2,"a"))]
1-element Vector{Data}:
 Data(1, NestedData(2, "a"))

julia> Serde.to_csv(data)
"id,nest_id,nest_name\n1,2,a\n"

julia> csv = Serde.deser_csv(Data,csv)
ERROR: ParamError: parameter 'nest::NestedData' was not passed or has the value 'null'

Of course, this issue should be put on hold until we properly constrain Union types during serialization.

gryumov commented 3 days ago

It might seem easy to just use a delimiter, but what if the delimiter is also part of the data itself?

struct NestedData
    id::Int
    name_name::String <----
end