Is there a straightforward way to pass an array of arrays, or even better, something approximating an arbitrary JSON-like object to a macro?
Consider the following code:
{{velocity}}
#set($myvar = [ [0,0], [1,2] ] )
$myvar.class.name
#foreach($i in $myvar)
$i
#foreach($j in $i)
$j
#end
#end{{testMacro param=“[0,0], [1,2]”/}}
{{/velocity}}
The code in testMacro is essentially the same:
{{velocity}}
INSIDE TESTMACRO
#set($myvar = $wikimacro.parameters.param)
$myvar.class.name
#foreach($i in $myvar)
$i
#foreach($j in $i)
$j
#end
#end{{/velocity}}
The parameter “param” is defined to be of type “java.util.ArrayList”.
Here’s the output:
java.util.ArrayList
[0, 0]
0
0
[1, 2]
1
2INSIDE TESTMACRO
java.util.ArrayList
[0
0]
[1
2]
So: in the first set of code, the #set() is correctly parsing a list of lists. However, when passing the same thing to the macro, the parser is not paying any attention to the structure inside the list, just doing a dumb comma separation.
I have likewise been having difficulties passing a map to a macro.
Is it possible to pass data objects like this to a macro, and do you have any examples that show how to do it?