From a39c2709130d1618c62b29f356f36f9ce70a30dc Mon Sep 17 00:00:00 2001 From: Michel Davit Date: Mon, 22 Jul 2024 10:30:02 +0200 Subject: [PATCH] Use setStringType helper for schema --- .../main/scala/magnolify/avro/AvroType.scala | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/avro/src/main/scala/magnolify/avro/AvroType.scala b/avro/src/main/scala/magnolify/avro/AvroType.scala index b89144c7..d9e8eaf6 100644 --- a/avro/src/main/scala/magnolify/avro/AvroType.scala +++ b/avro/src/main/scala/magnolify/avro/AvroType.scala @@ -203,12 +203,11 @@ object AvroField { implicit val afCharSequence: AvroField[CharSequence] = id[CharSequence](Schema.Type.STRING) implicit val afString: AvroField[String] = new Aux[String, String, String] { - override protected def buildSchema(cm: CaseMapper): Schema = - SchemaBuilder - .builder() - .stringBuilder() - .prop(GenericData.STRING_PROP, GenericData.StringType.String) - .endString() + override protected def buildSchema(cm: CaseMapper): Schema = { + val schema = SchemaBuilder.builder().stringType() + GenericData.setStringType(schema, GenericData.StringType.String) + schema + } override def from(v: String)(cm: CaseMapper): String = v override def to(v: String)(cm: CaseMapper): String = v } @@ -272,11 +271,11 @@ object AvroField { implicit def afStringMap[T](implicit f: AvroField[T]): AvroField[Map[String, T]] = new Aux[Map[String, T], ju.Map[String, f.FromT], ju.Map[String, f.ToT]] { - override protected def buildSchema(cm: CaseMapper): Schema = - SchemaBuilder - .map() - .prop(GenericData.STRING_PROP, GenericData.StringType.String) - .values(f.schema(cm)) + override protected def buildSchema(cm: CaseMapper): Schema = { + val schema = SchemaBuilder.map().values(f.schema(cm)) + GenericData.setStringType(schema, GenericData.StringType.String) + schema + } override def fallbackDefault: ju.Map[String, f.ToT] = ju.Collections.emptyMap() override def from(v: ju.Map[String, f.FromT])(cm: CaseMapper): Map[String, T] = v.asScala.map { case (k, v) => k -> f.from(v)(cm) }.toMap