How to cast inner classes from Dynamic Message in Protobuf?

为君一笑 提交于 2020-06-29 03:37:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!