protobuf構造の特定のフィールドをマスクする方法が見つかりませんでした。私はFieldMaskUtilについて読んだことがありますが、いくつかの例を試しましたが、逆にFieldMaskに記載されているコピーフィールドが、私が望んでいたものと異なっているようです。サンプル構造と対応するテストコードは次のとおりです。Protobufの特定のフィールドをマスクする方法
プロト:
syntax = "proto3";
package model;
option java_package = "test.demo.services.protobuf.customer.model";
option java_outer_classname = "CustomerProto";
message Accounts {
repeated Account account = 1;
}
message Account {
int32 id = 1;
string number = 2;
int32 customer_id = 3;
}
message Customers {
repeated Customer customers = 1;
}
message Customer {
int32 id = 1;
string pesel = 2;
string name = 3;
CustomerType type = 4;
repeated Account accounts = 5;
enum CustomerType {
INDIVIDUAL = 0;
COMPANY = 1;
}
}
はここでサンプルテストコード
package test.demo.services.protobuf.customer.model;
import org.junit.Test;
import test.demo.services.protobuf.customer.model.CustomerProto.Customer;
import com.google.protobuf.util.FieldMaskUtil;
public class TestMerge {
@Test
public void eraseFields() {
Customer request = Customer.newBuilder().setId(10).setPesel("12345").setName("Harry Alto").build();
// Erase name
Customer.Builder modifieldRequest = Customer.newBuilder();
FieldMaskUtil.merge(FieldMaskUtil.fromString("name"), request, modifieldRequest);
System.out.println(modifieldRequest.build().toString());
}
}
がここに出力だだ:
私が期待しているだろう何name: "Harry Alto"
は、他のすべてのものを印刷しますより私は
私が期待しているだろう何
感謝のために@cnaurothに感謝します。提案されたソリューションに感謝します。しようとします。 – Harry
お客様のprotobufをお持ちで、各カスタマーの各protobuf内で名前フィールドをマスクしたい場合はどうなりますか?私は繰り返しフィールドに対処する方法がわかりません。 – junecng