I have a proto message:
syntax = "proto3";
import "google/protobuf/any.proto";
message Task {
repeated google.protobuf.Any targets = 1;
// ...
}
message Target {
string name = 1;
// ...
}
How should I add Target messages into Task.targets
?
In official docs I've found info about how to assign value to a single Any type value, however in my case I have repeated Any
field type.
Edit: Task.targets
may contain different types of targets, that's why Any
type is used. A single Target
message is just for minimal reproducible example.
After searching for an answer myself, I found this thread to be the most relevant so I'll post my solution here if it helps anyone (but in Java/Scala).
If you want
and
targets
can be any value such as (string, bool, int, etc). This is how I did it in scala/java: