diff --git a/mongo/mongo-3/src/main/scala/io/sphere/mongo/format/MongoFormat.scala b/mongo/mongo-3/src/main/scala/io/sphere/mongo/format/MongoFormat.scala index ffcf985..85b73db 100644 --- a/mongo/mongo-3/src/main/scala/io/sphere/mongo/format/MongoFormat.scala +++ b/mongo/mongo-3/src/main/scala/io/sphere/mongo/format/MongoFormat.scala @@ -59,10 +59,7 @@ object MongoFormat { inline private def deriveTrait[A](mirrorOfSum: Mirror.SumOf[A]): MongoFormat[A] = new MongoFormat[A] { private val traitMetaData = AnnotationReader.readTraitMetaData[A] - private val typeHintMap = traitMetaData.subtypes.collect { - case (name, classMeta) if classMeta.typeHint.isDefined => - name -> classMeta.typeHint.get - } + private val typeHintMap = traitMetaData.subTypeTypeHints private val reverseTypeHintMap = typeHintMap.map((on, n) => (n, on)) private val formatters = summonFormatters[mirrorOfSum.MirroredElemTypes] private val names = constValueTuple[mirrorOfSum.MirroredElemLabels].productIterator.toVector diff --git a/mongo/mongo-3/src/main/scala/io/sphere/mongo/generic/AnnotationReader.scala b/mongo/mongo-3/src/main/scala/io/sphere/mongo/generic/AnnotationReader.scala index 7b5c5a9..bcf32d8 100644 --- a/mongo/mongo-3/src/main/scala/io/sphere/mongo/generic/AnnotationReader.scala +++ b/mongo/mongo-3/src/main/scala/io/sphere/mongo/generic/AnnotationReader.scala @@ -28,6 +28,11 @@ case class TraitMetaData( subtypes: Map[String, CaseClassMetaData] ) { val typeDiscriminator: String = typeHintFieldRaw.map(_.value).getOrElse("type") + + val subTypeTypeHints: Map[String, String] = subtypes.collect { + case (name, classMeta) if classMeta.typeHint.isDefined => + name -> classMeta.typeHint.get + } } object AnnotationReader {