scalalandio / chimney

Scala library for boilerplate-free, type-safe data transformations

Home Page:https://chimney.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[PartialTransformer] Field Option[Field].None to Proto3.Fields.Default

ps-rterzman opened this issue · comments

Hello,
I am trying to use PartialTransfomer for achieving domain to proto3 transfomration.
I faced an issue related to missed fields in domain case class even if proto3 fields are optional with default value.

Domain case class
final case class ClientProductEntity(id: Option[String], promotions: Option[Seq(Promo)], PSCategory: Option[String]) final case class Promo(effectiveStartDate: Option[Long], effectiveEndDate: Option[Long], map: Seq[Map])

Proto3
@SerialVersionUID(0L) final case class ClientProduct( id: _root_.scala.Predef.String = "", releaseDate: _root_.scala.Option[_root_.scala.Long] = _root_.scala.None, promotions: _root_.scala.Seq[com.pricespider.unity.domain.ClientProduct.Promo] = _root_.scala.Seq.empty), pSCategory: _root_.scala.Option[_root_.scala.Predef.String] = _root_.scala.None)

PartialTransformers:
val mappingResult: Either[Result.Errors, ClientProduct] = clientProductEntity .intoPartial[ClientProduct] .withFieldRenamed(_.PSCBID, _.pSCBID) .withFieldRenamed(_.PSCID, _.pSCID) .withFieldRenamed(_.PSCPID, _.pSCPID) .withFieldRenamed(_.PSCategory, _.pSCategory) .withFieldComputed(_.pSPID, from => from.PSPID.orNull) .withFieldConst(_.unknownFields, _root_.scalapb.UnknownFieldSet.empty) .enableOptionDefaultsToNone .transform .asEither .asOption .orNull

mappingResult.right is None
mappingResult.left contains all missed values

I am wondering is there any way to map missed | Option values with default values. Could you help me with that?