Search code examples
javapythonjythongrinder

arg can't be coerced to java.util.List? Could any one tell me whats wrong in my code please?


myDict = {'itemkey1':'itemvalue1', 'itemkey2':'itemkey2','itemkey3':'itemvalue3','itemkey4':'itemvalue4'};

event = portTest.event(myDict);

I am getting the following error

Aborted run: Jython exception: TypeError:arg can't be coerced to java.util.List

myDict is the array of key values.

i hope i am passing the correct syntax in myDict for keyvalue[] datalist as it just got key value pair.

public Response event(KeyValue[] dataList)

I am calling the event function in java from jython script using grinder tool.


Solution

  • You'll need to turn your dictionary into a series of keys and values:

    def chainDict(mapping):
        items = []
        for item in mapping.iteritems():
            items.extend(item)
        return items
    
    event = portTest.event(chainDict(myDict))
    

    This'll pass a list of [keyFoo, valueFoo keyBar, valueBar] to the event method, where keys and values are paired but in arbitrary order.

    If you don't have an itertools module available, chain can be defined as: