Use setField() Java API for maps

19 views
Skip to first unread message

Jin Sun

unread,
Jun 8, 2020, 5:05:40 AM6/8/20
to Protocol Buffers
I have a map<string, string> field in a message. When I try to use setField(Descriptors.FieldDescriptor field, Object value) API on Message.Builder and pass in a descriptor with a Java map, it complains map cannot be converted to a list.
I want to replace the existing map with the new map. Just wondering what should I pass in for value argument.
Thanks.

Jin Sun

unread,
Jun 8, 2020, 11:02:43 PM6/8/20
to Protocol Buffers
I solved the problem by passing in a list of MapEntry. For instantiating MapEntry, use descriptor from the map field.
Reply all
Reply to author
Forward
0 new messages