zio-schema icon indicating copy to clipboard operation
zio-schema copied to clipboard

Schema and DynamicValue should preserve tuple structures when schema got serialized

Open vigoo opened this issue 2 years ago • 2 comments

The simple round-trip test for DynamicValue:

Given a value a: A and a schema: Schema[A] if we convert it to dynamic value and back:

schema.fromDynamic(schema.toDynamic(a)))

we get back the same value a. This property is verified by tests and it is true for all the supported cases.

However if we serialize the schema and read it back:

scala

val schemaAst = schema.ast
val schema2   = schemaAst.toSchema

and try to materialize the dynamic value with schema2, simulating that the value and its schema was sent to another process, the property is no longer true for all cases:

  • Records and enums are materialized as generic ListMap[String, _] values which is expected
  • However we also loose the structure of tuples!
    • higher arity tuples are converted back to a nested representation (A, B, C) becomes ((A, B), C)

I think for tuples we should be able to reconstruct the original tuple arity in this case.

vigoo avatar Sep 25 '22 10:09 vigoo

I'll work on this one

mjabari avatar Sep 30 '22 12:09 mjabari