-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
It appears that at some point during conversion to protobuf entity-builder instance cache is used, but it looks like builders are mutable and are not reset to initial clean state which leads to incorrect results.
Reproduction (click to expand):
Given
definition.proto
:
syntax = "proto3";
message DataEntryPb {
string key = 1;
string value = 2;
}
message EntityPb {
string entityId = 1;
repeated DataEntryPb metadata = 2;
}
message MultiEntityPb {
string multiEntityId = 1;
repeated EntityPb entities = 2;
}
and
Reproduction.scala
:
import magnolify.protobuf._
object Reproduction extends App{
final case class DataEntry(key: String, value: String)
final case class Entity(entityId: String, metadata: Seq[DataEntry])
final case class MultiEntity(multiEntityId: String, entities: Seq[Entity])
val me = MultiEntity(
"me1",
Seq(
Entity("entity1", Seq(DataEntry("key1", "value1"))),
Entity("entity2", Seq.empty),
),
)
val pbType = ProtobufType[MultiEntity, Definition.MultiEntityPb]
val x = pbType.to(me)
println(x)
}
Produces the following:
multiEntityId: "me1"
entities {
entityId: "entity1"
metadata {
key: "key1"
value: "value1"
}
}
entities {
entityId: "entity2"
metadata {
key: "key1"
value: "value1"
}
}
Note that metadata is supposed to be empty for the second entity.
Metadata
Metadata
Assignees
Labels
No labels