0

I have a protobuf message with a repeated field:

message TestRepeatedMask {
  repeated Inner inner_message = 1;

  message Inner {
    optional string first = 1;
    optional string second = 2;
  }
}

I know the docs for fieldmasks state that you can't select one field from within each member of the list of elements, but OTOH there's this documentation for wildcards that says you can use ".*." within the fieldmask path to do exactly that.

My Java example:

  public static TestRepeatedMask readMinimal(TestRepeatedMask route) {
    FieldMask.Builder maskBuilder = FieldMask.newBuilder();
    FieldMask mask = maskBuilder.addPaths("inner_message.*.first").build();
    TestRepeatedMask.Builder result = TestRepeatedMask.newBuilder();
    FieldMaskUtil.merge(mask, route, result);
    return result.build();
  }

  @Test
  public void readRespo() {
    TestRepeatedMask o =
        SelectedRouteMasker.readMinimal(
            TestRepeatedMask.newBuilder()
                .addInnerMessage(Inner.newBuilder().setFirst("first").setSecond("second"))
                .build());
    System.out.println(o);
  }

I'm expecting to get this obect without the "second" field:

TestRepeatedMask { inner { first: "first" } }

I'm running the test and getting:

Oct 15, 2025 9:06:59 AM com.google.protobuf.util.FieldMaskTree merge
WARNING: Field "TestRepeatedMask.inner_message" is not a singular message field and cannot have sub-fields.

Is what I'm trying to do not supported? Am I misreading the wildcard docs?

1
  • Try inner_message.first. It's a good practice to pluralize repeated field names i.e. inner_messages. Commented Oct 24 at 20:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.