Remove empty message proto from another proto when using JsonFormat.Printer

Viewed 11

I'm trying to remove empty message proto from another proto after setting empty proto as we see here :

 TestProto test = TestProto.newBuilder().setCertification(CompanyCertification.newBuilder().build()).build();
        String output = JsonFormat.printer().print(test);
        System.out.println(output);

the output is:

{
  "certification": {
  }
}

how can I get only {} without the empty certification proto?

the messages proto :

   message TestProto{
     CompanyCertification certification = 1;
   }
    
    message CompanyCertification{
      bool certified = 1;
      int64 certificationDate = 2;
    }
0 Answers
Related