Skip to content

ArrayType serialization with 2D+ arrays #14

@Byrth

Description

@Byrth

Currently ArrayType() iterates element-wise over an array type using the default iterate(x::T) method when serializing. This has the effect of flattening higher dimensional arrays into vectors. Matrices, for instance, become vectors with no information about their original dimensions.

The JSON standard maintains array order, so it seems safe for me to serialize matrices as vectors of vectors. However, my only way to affect serialization is by overloading the iterate(x::T) function and doing so for the Matrix type seems likely to recompile large parts of Julia base (as well as break my own code.)

Then on deserialization, I would just construct(::Type{Matrix}, x::Vector) = hcat(x...)

It makes sense on some level that this would be natively unsupported because it makes the serialized representation of matrices and vectors of vectors indistinguishable (and thus deserialize(serialize(matrix)) != matrix without an additional construct definition), but that code doesn't work right now either and it seems like there should be some way to for users to enable support for it because matrices are so common. Perhaps there should be something analogous to construct() for serialization?

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