2

I want to generate below algebraic data types in scala using scalaPB.

trait MyEventCmd
case class MyEvent(mytype: Int, cp: Option[Double], value: Option[String] = None, id: Option[String] = None) extends MyEventCmd
case object Flush extends MyEventCmd

I've defined below protobuf myevent.proto-

syntax = "proto3";

message MyEventCmd {
  oneof sealed_value {
    Flush lit = 1;
    MyEvent event = 2;
  }
}

message Flush {
}

message MyEvent {
  int32 eType = 1;
  double cp = 2;
  string value = 3;
  string id = 4;
}

The problem with my definition is that Flush is generated as case class not case object.

Also, I don't know how to make field optional and with default value.

user51
  • 8,843
  • 21
  • 79
  • 158

1 Answers1

0

ScalaPB generates case classes even when there are no fields. There is no option available to generate case objects.

You can disable default values for all fields in a file (or a package) by setting no_default_values_in_constructor. See: https://scalapb.github.io/customizations.html#file-level-options

thesamet
  • 6,382
  • 2
  • 31
  • 42