YailDictionary constructor does not accept nested dictionaries

I encountered a problem when creating dictionaries in an extension. I’m not able to create nested dictionaries

public YailDictionary NestedDictionaryTest() {
        HashMap object = new HashMap();
        HashMap value = new HashMap();
        return new YailDictionary(object);

results in
I’m expecting HashMaps of HashMaps to be turned into dictionaries of dictionaries. Can somebody say if this was intended or not

Hi @Red_Panda,

It’s the case for both YailList and YailDictionary that they take their arguments as is. There’s a note on YailList specifically about this, that if you would rather pass back a list you should pass a List type that’s not YailList. The runtime will take care of sanitizing a Java List into a YailList. Runtime.scm assumes that if you hand back a YailList or YailDictionary you’ve taken the care to sanitize it yourself.

In your code, rather than returning new YailDictionary(object), you could just return object and the runtime should take care of the rest.


1 Like

Is this behaviour documented somewhere? Doing it my way with lists would be extremely confusing, because nested elements would be converted into strings, which look identical to lists

1 Like

It works the same way with Java Maps. You should be able to return a HashMap and the runtime will take care of the rest. This isn’t formally documented anywhere at the moment.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.