Omar Al-Safi created CAMEL-13988:
------------------------------------
Summary: Enable camel-protobuf to convert from objects of type Map
to Proto using the message descriptor
Key: CAMEL-13988
URL: https://issues.apache.org/jira/browse/CAMEL-13988
Project: Camel
Issue Type: New Feature
Affects Versions: 3.0.0.RC1
Reporter: Omar Al-Safi
Fix For: 3.x
Currently, when you marshal using camel-protobuf, it expects beforehand that
you have already created your protobuf message as you can see
[here|https://github.com/apache/camel/blob/master/components/camel-protobuf/src/main/java/org/apache/camel/dataformat/protobuf/ProtobufDataFormat.java#L129].
I think is beneficial if the user can marshal the data automatically to
protobuf provided he/she has the data in {{Map}} type and with the correct
instance class name is provided. We can achieve this with the following steps:
# In {{marshal}} method, we check if the graph object of type {{Map.class}}.
# If it is of type {{Map.class}}, then using the
{{defaultInstance.getDescriptorForType()}}, we obtain the [Message
Descriptor|https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Descriptors.Descriptor]
for the class instance.
# Using the obtained descriptor, we iterate over map value and set the field
from the descriptor.
By using this, the user can marshal data to Protobuf without the need to
process it before as long he/she has the data in type {{Map}}. I can send a PoC
PR if you guys find my proposal reasonable enough but from my the top of my
head, it shouldn't be much of work to add this feature to camel-protobuf
--
This message was sent by Atlassian Jira
(v8.3.2#803003)