Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support to serialize scala..MapWrapper same way as a regular Map #57

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.epiphanous.flinkrunner.serde

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.fasterxml.jackson.databind.{JsonSerializer, SerializerProvider}
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.typesafe.scalalogging.LazyLogging
import org.apache.avro.Schema
import org.apache.avro.Schema.Type._
Expand All @@ -12,6 +12,7 @@ import org.apache.flink.api.scala.createTypeInformation

import scala.annotation.tailrec
import scala.collection.JavaConverters._
import scala.collection.convert.ImplicitConversions.`map AsScala`

/** A simple custom jackson serializer to handle serializing avro records
* (Generic or Specific)
Expand Down Expand Up @@ -61,6 +62,7 @@ class AvroJsonSerializer
}
gen.writeEndArray()
case (MAP, map: Map[String, _] @unchecked) =>
case (MAP, map: scala.collection.convert.Wrappers.MapWrapper[String,Any] @unchecked) =>
gen.writeObjectFieldStart(name)
map.foreach { case (k, e) =>
gen.writeFieldName(k)
Expand Down Expand Up @@ -95,13 +97,13 @@ class AvroJsonSerializer
case (BOOLEAN, boolean: Boolean) =>
gen.writeBooleanField(name, boolean)
case _ =>
gen.writeFieldName(name)
provider
.findValueSerializer(
implicitly[TypeInformation[T]].getTypeClass
)
.asInstanceOf[JsonSerializer[T]]
.serialize(value, gen, provider)
gen.writeFieldName(name)
provider
.findValueSerializer(
implicitly[TypeInformation[T]].getTypeClass
)
.asInstanceOf[JsonSerializer[T]]
.serialize(value, gen, provider)
}
}

Expand All @@ -122,7 +124,7 @@ class AvroJsonSerializer
_serializeElement(e, schema.getElementType, gen, provider)
}
case (MAP, _) => gen.writeObject(value)
case (UNION, _) => // todo
case (UNION, _) => gen.writeString(value.toString)
case (STRING, string: String) => gen.writeString(string)
case (INT, int: Int) => gen.writeNumber(int)
case (LONG, long: Long) => gen.writeNumber(long)
Expand Down