问题
I am converting my protobuf response (byte[]
) to Dynamic message by using following code block
DynamicMessage message = DynamicMessage.parseFrom((Descriptors.Descriptor type, byte[] data)
By using getField()
, I am able to get field values in the form of java objects,
FieldDescriptor fieldDescriptor = message.getDescriptorForType().findFieldByName("fieldXyz");
Object A = message.getField(fieldDescriptor);
But I want to cast the value to original protobuf class. For example in this object A
contains List<Event>
where Event
is another protobuf class object. I want to get this object as it is.
By doing so I get the following exception.
java.lang.ClassCastException: com.google.protobuf.DynamicMessage cannot be cast to
Am I doing right ?
来源:https://stackoverflow.com/questions/62578935/how-to-cast-inner-classes-from-dynamic-message-in-protobuf