I am trying to find the best approach to print multiple protobuf generated Java classes to a custom human readable JSON format.
Given following code that uses Java class generated from protobuf:
Person.Builder personBuilder = PersonData.newBuilder();
Person person = personBuilder
.setName("John Doe")
.setAge("99")
.build();
The following is the default JSON representation when using new JsonFormat().printToString(person):
{ "name": "John Doe", "age":99 }
The desired JSON representation is:
"John Doe":{
"age":99
}
Is there a common generic way to achieve the above for multiple protobuf models?