-
Notifications
You must be signed in to change notification settings - Fork 2
Serialization and Marshaling (again) #590
Description
Just capturing ideas for discussion.
History
Another thing, we actively decided after a 2 year process not to define the "schema" for serialization. We originally had a protobuf packing approach which was hard schema type dependent and which supported forward-backward multilanguage compatibility. After much pain, we decided that top level packing MUST be JSON, and that the JSON string must at top level include the format in which the data is serialized. This is to mimic how the Internet has standardized it's data exchange format. So StructTypes.jl might be a real problem given the history on serialization.
So to stress, its probably not a good idea going down a path to unilaterally "change everything" on serialization.
In this case, it will be better to understand what the problems are with JSON.jl JSON2.jl JSON3.jl, because clearly they haven't figured it all out either. But we likely won't go down writing JSON4.jl either.
Also remember that the whole point of JSON is that serialization should be marginally or completely available outside Julia. The ZMQ interface for example is about multilanguage support and it uses the same serialization. The DB storage is definitely not a Julia implementation, later we will add a FuseDFG driver, etc, etc. A little while back we came up with the requirement that ZMQ messages should be exactly the same as FileDFG content. The schema discussion becomes a whole issue there. There are 100 different schema's available... So serialization only has 2nd best answers for everything. Whenever you pick the "best" answer for one requirement, then all others get real upset. So we have to accept a 2nd best solution for everybody and JSON is the best bet at this time.
So JSON
Options
JSON.jl + unmarshal.jl
...
JSON2.jl
Deprecated in favor of JSON3
JSON3.jl
See this for the 2 trait options: Struct() or Mutable()
In short Struct() is fast, but the order is important (So has to be preserved if created/modfied from outside).
Example:
julia> using JSON3
julia> using DistributedFactorGraphs
julia> using TimeZones
julia> using UUIDs
julia> bse = BlobStoreEntry(:a, uuid4(), :abc, "", "", "", "", ZonedDateTime("2020-08-11T14:32:27.000+02:00"))
BlobStoreEntry(:a, UUID("a533d151-764a-425d-9e57-a8f194577866"), :abc, "", "", "", "", ZonedDateTime(2020, 8, 11, 14, 32, 27, tz"UTC+02:00"))
julia> JSON3.StructTypes.StructType(::Type{BlobStoreEntry}) = JSON3.StructTypes.Struct()
julia> json3_str = JSON3.write(bse)
"{\"label\":\"a\",\"id\":\"a533d151-764a-425d-9e57-a8f194577866\",\"blobstore\":\"abc\",\"hash\":\"\",\"origin\":\"\",\"description\":\"\",\"mimeType\":\"\",\"createdTimestamp\":\"2020-08-11T14:32:27.000+02:00\"}"
julia> JSON3.read(json3_str, BlobStoreEntry)
BlobStoreEntry(:a, UUID("a533d151-764a-425d-9e57-a8f194577866"), :abc, "", "", "", "", ZonedDateTime(2020, 8, 11, 14, 32, 27, tz"UTC+02:00"))