Why Are Moqui Parameters of Type Map Treated as java.lang.String Instead of LinkedHashMap?

I noticed an interesting behavior when working with parameters in Moqui. If I send a map-like structure as a parameter, for example:

[name: "Jerry", age: 42, city: "New York"]

When I check its class type in Moqui’s context, I get java.lang.String. However, if I define the same structure statically in Groovy code like this:

def staticType = [name: "Jerry", age: 42, city: "New York"]
println "itemsType " + staticType.getClass().getName()

The type is java.util.LinkedHashMap.

Why is the parameter treated as a java.lang.String? Is there a way to directly work with it as a Map in Moqui?

Here’s the overall code for context:

    <service verb="test" noun="Service">
        <in-parameters>
            <parameter name="item" type="Map" />
        </in-parameters>
        <actions>
            <script><![CDATA[
                def itemType = item.getClass().getName()
                println "itemsType " + itemType // java.lang.String 

                def staticType = [name: "Jerry", age: 42, city: "New York"]
                println "itemsType " + staticType.getClass().getName() // java.util.LinkedHashMap
            ]]></script>
        </actions>
    </service>

Any insights would be appreciated!

I believe this is because you’re testing it from the tools section, which cannot input a map, and therefore you get passed a string even if you write it as a map. You’re just testing in the wrong place.

To actually see a map, what you want is to create another service, and hard-code a map from that service to call it to the other service, and then observe that you’re receiving a map. For example:

    <service verb="input" noun="TheMap">
        <actions>
            <script><![CDATA[
                ec.service.sync()
                        .name('MyTests.test#MapInput')
                        .parameter('testMap', [a: 1, b: 2])
                        .call()
            ]]></script>
        </actions>
    </service>

    <service verb="test" noun="MapInput">
        <in-parameters>
            <parameter name="testMap" type="Map" />
        </in-parameters>
        <actions>
            <script><![CDATA[
                println '================================='
                println testMap
                println testMap.getClass()
            ]]></script>
        </actions>
    </service>