Skip to content

Lower with respect to serialization context #299

@twavv

Description

@twavv

Would it be possible to pass the serialization context to JSON.lower? Typically, the thing I want to override is the shape of the thing that's being lowered rather than the formatting and this would make it much easier.

e.g. I could define a VerboseSerializationContext and just have overloads of the form

function JSON.lower(::VerboseSerializationContext, s::MyStruct)
    return Dict(
        "debugId" => ...,
    )
end

One issue with the proposal above is that it would probably require existing definitions of JSON.lower(x::MyType) = ... to be re-written as JSON.lower(::CommonSerialization, x::MyType). Either that or define

# Let the single-arg form be the "common" form
JSON.lower(::CommonSerialization, x::Any) = JSON.lower(x)

which wouldn't be breaking (afaict).

If there are better ways to do what I'm describing, I'm all ears! :^)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions