There is a Map called “content” in the template I wrote and I can get the “content” field from CreatedEvent by using
List<ValueOuterClass.RecordField> list = e.getCreateArguments().getFieldsList();
ValueOuterClass.RecordField content = list.stream().filter(x -> x.getLabel().equals("content")).findAny().get();
ValueOuterClass.Map map = content.getValue().getMap();
Does anyone know how to retrieve the value by label/key from the map? i.e. map.getEntry(String key). The closest I can find is map.getEntries(int index) but I don’t want to search the whole map. Thanks.
ValueOuterClass.Map is the serialized representation of you Daml map in protobuf. From java point of view, you should better see this data structure as an association list, in other words you will need to either convert this list yourself into a Hash/TreeMap or directly search inside.
Note that the ledger API guarantees you the association has no duplicate and is sorted by key (be careful Daml assumes UTF8 ordering).
The reason why we are not using protobuf generic map, is we want to enforce ordering on the wire while generic maps do not allow us to do that.
Hope this helps.