Hi,

I try to convert the Java representation of a protobuf message into another 
message with the same fields (ordering, names, types). I try to do it the 
following way but this ends in a java.lang.InstantiationException:

public static <T extends GeneratedMessage> T 
commandToEvent(GeneratedMessage command,
Class<T> clazz) {
try {
Builder builder = clazz.newInstance().newBuilderForType();
Map<FieldDescriptor, Object> fields = command.getAllFields();
for(Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
builder.setField(entry.getKey(), entry.getValue());
}
return (T)builder.build();
} catch (Exception e) {
Throwables.propagate(e); 
} 
return null;
}

Does somebody has an idea how to do this?

Thanks,
Tobias 

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/protobuf/-/lhtLryvHEJsJ.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to