Skip to content

Add extension to make TimeArray JSON3 serializable #535

Open
@ValentinKaisermayer

Description

@ValentinKaisermayer

The main problem is that a TimeArray is a parametric type, which is difficult to implement, see.

The meta::Any field is not serializable as a JSON in any case.
JSON.json even results in a stack overflow error.

This does work, but still makes the assumption that the timestamps are DateTime.
They can be anything: Date, DateTime, TimeZones.ZonedDateTime, TimesDates.TimeDate, TimesDates.TimeDateZone

StructTypes.StructType(::Type{<:TimeSeries.TimeArray}) = StructTypes.CustomStruct()
function StructTypes.lower(x::TimeSeries.TimeArray)
    return Dict(
        "timestamp" => TimeSeries.timestamp(x),
        "values" => [TimeSeries.values(x[c]) for c in TimeSeries.colnames(x)],
        "colnames" => String.(TimeSeries.colnames(x)),
    )
end
function StructTypes.construct(::Type{TimeSeries.TimeArray}, x)
    return TimeSeries.TimeArray(
        Dates.DateTime.(x["timestamp"]),
        reduce(hcat, x["values"]), 
        Symbol.(x["colnames"]),
    )
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions