Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower with respect to serialization context #299

Open
twavv opened this issue Jan 5, 2020 · 1 comment
Open

Lower with respect to serialization context #299

twavv opened this issue Jan 5, 2020 · 1 comment

Comments

@twavv
Copy link

twavv commented Jan 5, 2020

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! :^)

@TotalVerb
Copy link
Collaborator

I think your second proposal (the JSON.lower(::CommonSerialization, x::Any) = JSON.lower(x)) is pretty reasonable, and is compatible with the direction we've gone (support for serialization contexts while making it "easy" to use the default one). A PR is certainly welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants