wdl
wdl copied to clipboard
Allow serialization/deserialization of `Pair` to/from JSON array
In WDL 1.1, serialization/deserializaton of Pair is not supported.
Since JSON arrays are allowed to be heterogeneous, we should support serialization of Pair[X, Y] to [X, Y] (as long as X and Y are both serializable) and deserialization of a heterogeneous two-element array [X, Y] to Pair[X, Y]. A homogeneous two-element array [X, X] would still deserialize to Array[X] and would require coercion to Pair[X, X].
This would also enable serialization of Map[X, Y] to an array of arrays, for X types other than String.
This change will affect the following areas of the spec:
write_jsonwill support serialization ofPairs andMaps of any typeread_jsonwill support deserialization of a heterogeneous two-element arrays to aPair, and of an array of heterogeneous two-element arrays to aMap- Coercion of
Array[X]toPair[X, X]will be supported for an array of exactly two elements - The standard input/output JSON format will use array as the serialization format for a
Pair, and array-of-arrays as the serialization format for aMapwith non-Stringkeys
Overall I am supportive of this idea, although I think the expectation has been a pair would be serialized into something that looks like: { "left": ... , "right": }
I wonder how common the situation is where someone would want a heterogenous pair
That is an option.
I like using an array because it doesn't require us to introduce a new custom format. Trying to deserialize a heterogeneous array into anything other than a Pair will fail. You could deserialize a homogeneous Pair into an array, but you could also deserialize {"left": X, "right": X} to a Map. There's no unambiguous serialization format for a Pair so in that case I'd argue to just go for the simplest solution.
we should determine what the current engines do in this scenario, do they fail or do they have some sort of intermediary type conversion