Retrieve value from com.daml.ledger.api.v1.ValueOuterClass.Map

Hi there,

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.

Hey Frankie,

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.

1 Like