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

Default serialization method for structs #139

Closed
Octogonapus opened this issue Apr 6, 2021 · 3 comments
Closed

Default serialization method for structs #139

Octogonapus opened this issue Apr 6, 2021 · 3 comments

Comments

@Octogonapus
Copy link

I am new to this library so please let me know if I am missing something, but why isn't the default serialization method for a struct StructTypes.Struct()? This means that if I need to serialize some struct, I need to implement

StructTypes.StructType(::Type{Foo}) = StructTypes.Struct()

for every struct I need to serialize, including types I don't own and/or don't interface with directly. I think that StructTypes.Struct() would be a sensible default.

@quinnj
Copy link
Owner

quinnj commented Apr 7, 2021

This was discussed and was the default for a short period of time, but it led to some hard-to-figure-out bugs where things accidentally serialized, but not in the way you wanted. Because everything was a Struct, it made for some weirdness. We could maybe consider changing it since the StructTypes API has matured quite a bit, but I'm still hesitant given those initial bug reports we saw.

Can you comment more on the cases you're running into w/ types you don't own? If they're in Base or stdlibs, we can define them in JSON3.jl or StructTypes.jl. Otherwise, it might be worth contacting the type package owners and seeing if we can work something out.

@Octogonapus
Copy link
Author

One type was VersionNumber in Base. Otherwise, in my case, the other types were all from internal packages. Needing to implement a StructType method for all my serializable types doesn't prevent me from using JSON3.jl, it's just an unexpected requirement after using JSON.jl.

quinnj added a commit to JuliaData/StructTypes.jl that referenced this issue Apr 13, 2021
It already satisfies the `StringType` interface, so it's an easy
definition. Fixes one issue mentioned in
quinnj/JSON3.jl#139.
@quinnj
Copy link
Owner

quinnj commented Apr 13, 2021

Ah, yeah, that's a good one. It's really easy to add a default definition for that, as you can see in my PR here: JuliaData/StructTypes.jl#44. Let me know if you run into any other issues where we could ahve default definitions that would be helpful.

quinnj added a commit to JuliaData/StructTypes.jl that referenced this issue Apr 13, 2021
It already satisfies the `StringType` interface, so it's an easy
definition. Fixes one issue mentioned in
quinnj/JSON3.jl#139.
@quinnj quinnj closed this as completed Apr 13, 2021
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