I'm trying to get the result of a JavaScript call to resemble a JSON structure of Map<String,Object> where the values may be number, string, boolean, objects (Maps) or arrays (Lists), similar to what Jackson does if you convert a value to a map.
When using the Value.as(Map.class)
call I would expect the values in the Map to follow these rules
If the raw Map.class or an Object component type is used, then the return types of the the list are subject to Object target type mapping rules recursively.
Further down the documentation (rule 8 of Object mapping)
If the value has array elements and it has an array size that is smaller or equal than Integer.MAX_VALUE then the result value will implement List.
However this test fails
public class TestGraalMap {
static String JS_CODE = "(function myFun(){ return { listProperty: ['listValue']};})";
@Test
public void testList() {
try (Context context = Context.create()) {
Value value = context.eval("js", JS_CODE);
Value result = value.execute();
Map<String,Object> resultMap = result.as(Map.class);
assertThat(resultMap).hasEntrySatisfying("listProperty", testArray -> {
assertThat(testArray).asList().containsExactly("listValue");
});
}
}
}
with the following error.
Expecting:
<{}>
to be an instance of:
<java.util.List>
but was instance of:
<com.oracle.truffle.polyglot.PolyglotMap>
What am I missing?