I am getting error like ListVariable cannot be cast to java.util.List


#1

I am calling the api which having the response in the form of List<List> and want to convert that response into the Table variable in Bot task.

I am getting error like java.lang.ClassCastException: org.webharvest.runtime.variables.ListVariable cannot be cast to java.util.List

<?xml version="1.0" encoding="UTF-8"?>

<config xmlns="http://web-harvest.sourceforge.net/schema/1.0/config"
    	scriptlang="groovy">
<robotics-flow>

    	<robot driver="universal" close-on-completion="true"
    			start-in-private="true">

    			<capability name="SEARCH_ALL_WINDOWS" value="true" />

    			<http url="http://localhost:8080/data">
    				<var-def name="data_api">
    					<http url="http://localhost:8080/data/list" method="GET" >
    					</http>
    				</var-def>
    			</http>

    			<script><![CDATA[
    				import com.workfusion.studio.rpa.recorder.api.internal.representation.*

    				import com.workfusion.studio.rpa.recorder.api.*

    				import com.workfusion.studio.rpa.recorder.api.types.*

    				import com.workfusion.studio.rpa.recorder.api.custom.*

    				import static com.workfusion.studio.rpa.recorder.api.RandomValues.CharacterSet.*

    				def data = RTable.builder().build()

    				enableTypeOnScreen()
    				
    				for (var in ${data_api}) {
    					data.addRow(var)
    				}

    			]]></script>
    			
    			

    		</robot>

    	</robotics-flow>

    	<export include-original-data="true" />

    </config>

#2

@abhimanyu_thit try writing data_api in the loop without the dollar sign and brackets.

for (var in data_api) {
	data.addRow(var)
}

Let me know if it doesn’t work for you.


#3

@ashapkina It is not working may be because,

If I print class println data_api.getClass(); then it shows
class org.webharvest.runtime.variables.ListVariable
If I print class println data_api.get(0).getClass(); then it shows
class org.webharvest.runtime.variables.NodeVariable.