0

I write proto like this

message I {
    google.protobuf.DoubleValue supplierCommissionAmount = 1;

}

It convert to below code

final case class I(
    variable: _root_.scala.Double = 0.0,
    
)

but I expect to be Option[Double]

final case class I(
    variable : _root_.scala.Option[_root_.scala.Double] = _root_.scala.None,

    
)

How to solve it

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • https://stackoverflow.com/questions/42622015/how-to-define-an-optional-field-in-protobuf-3 – Dmytro Mitin Jan 25 '23 at 23:00
  • Does adding `optional` solve your question? – Dmytro Mitin Jan 25 '23 at 23:03
  • Optional and oneof can not solve – Panida Yimsanga Jan 25 '23 at 23:31
  • 1
    Looks like you are out of luck: "In proto2, optional fields are represented as Option[]. In proto3, optional primitives are not wrapped in Option[], but messages are." https://scalapb.github.io/docs/getting-started/ – Dima Jan 25 '23 at 23:54
  • @PanidaYimsanga *"Optional and oneof can not solve"* Please see https://github.com/DmytroMitin/protobufdemo I [added](https://github.com/DmytroMitin/protobufdemo/blob/main/src/main/protobuf/myproto.proto#L11) `optional double d = 6` and I [can see](https://github.com/DmytroMitin/protobufdemo/blob/main/target/scala-2.13/src_managed/main/scalapb/com/example/myproto/MyClass.scala#L15) `d: _root_.scala.Option[_root_.scala.Double] = _root_.scala.None`. What am I doing wrong to reproduce? – Dmytro Mitin Jan 26 '23 at 06:41
  • @Dima ^^^^^^^^^ – Dmytro Mitin Jan 26 '23 at 06:42
  • @PanidaYimsanga Are we using different versions? – Dmytro Mitin Jan 26 '23 at 06:46
  • @PanidaYimsanga Also it's `Option` with `google.protobuf.DoubleValue` instead of `double` https://github.com/DmytroMitin/protobufdemo/commit/344834ff22baaf09364f21488fff7f29c95f3fcb – Dmytro Mitin Jan 26 '23 at 07:23

0 Answers0