how to map Object type variable of java in protobuf 3 for grpc

149 views Asked by At

I have class with below properties in my service, I want to create a grpc service for this. but i am not able to find how can i map Object data in protobuf.

public class FeatureDetails {

 private String type;
 private Object value;
 private String label;
 private Object options; }

I want protobuf for above variable which are of type Object

I have tried below code in protobuf.

oneof value {

 string string_value = 4;
 int32 int_value = 5;
 bool bool_value = 6;
 double double_value = 7;   }  

 google.protobuf.Any value=8

But I am getting null in value & options for both the cases after

1

There are 1 answers

0
San P On

You will need to extend protobuf for using Any type with your own java.lang.Object type for the options field. This is described in https://protobuf.dev/reference/java/api-docs/com/google/protobuf/Any.Builder.html or https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Any.Builder