You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When manually creating a record codec, then it is possible to define default values for fields. This works most of the time, but it will not work if the value is a collection or has a nested collection that contains records. See the following example to reproduce the issue:
importvulcan.Codecimportvulcan.generic.*caseclassElement(value: String)
caseclassCollection(elements: List[Element])
implicitvalelementCodec:Codec[Element] =Codec.derive
implicitvalcollectionCodec:Codec[Collection] =Codec.record(
name ="Collection",
namespace ="whatever",
)(field => field(name ="elements", access = _.elements, default =Some(List(Element("a")))).map(Collection.apply))
println(collectionCodec.schema) // Left(AvroError(org.apache.avro.AvroRuntimeException: Unknown datum class: class org.apache.avro.generic.GenericData$Record))
The bug is caused by a missing case in vulcan.internal.schema.adaptForSchema(Any). There is a recursion for IndexedRecord, but it would also need to recurse on the elements of java.util.Collection or java.util.List (the actual type of encoded is java.util.ArrayList according to the debugger).
If the field elements in the example above is Map[String, Element] instead of a List[Element], then the schema could also not be generated, because encoded would be a JavaCollectionWrappers.MapWrapper, which is also not handled.
The text was updated successfully, but these errors were encountered:
When manually creating a record codec, then it is possible to define default values for fields. This works most of the time, but it will not work if the value is a collection or has a nested collection that contains records. See the following example to reproduce the issue:
The bug is caused by a missing case in
vulcan.internal.schema.adaptForSchema(Any)
. There is a recursion forIndexedRecord
, but it would also need to recurse on the elements ofjava.util.Collection
orjava.util.List
(the actual type ofencoded
isjava.util.ArrayList
according to the debugger).If the field
elements
in the example above isMap[String, Element]
instead of aList[Element]
, then the schema could also not be generated, becauseencoded
would be aJavaCollectionWrappers.MapWrapper
, which is also not handled.The text was updated successfully, but these errors were encountered: