vendredi 3 avril 2020

Groovy : Class.forName().newInstance() error

I have this following method in which I return a List<ImField> object using the List<GPathResult> filteredList. I perform filteredList.each closure where I generate class at runtime and assign it a static type of ImField.

static List<ImField> getFields(GPathResult root,String fieldClass, String fieldType){
        List<GPathResult> filteredList = root.children().findAll{
            XMLSlurperUtil.name(it as GPathResult) == fieldType
        } as List<GPathResult>
        List<ImField> fields = []
        filteredList.each{GPathResult it,  int index ->
            fields.add(Class.forName(fieldClass).newInstance() as ImField)
            fields[index].set(it)
        }
        fields
}

The function call would look like so :

ImStageUtil.getFields(root, ImFieldFactory.SOURCE_FIELD, ImParserConstants.SOURCE_FIELD)

where ImFieldFactory.SOURCE_FIELD = "com.datametica.starling.informatica.dto.fields.SourceField" and ImParserContants.SOURCE_FIELD = "SOURCEFIELD"

the error occurs at the .each closure line:

No signature of method: com.datametica.starling.informatica.extractor.ImStageUtil$_getFields_closure11.doCall() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: []
Possible solutions: doCall(groovy.util.slurpersupport.GPathResult, int), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)
groovy.lang.MissingMethodException: No signature of method: com.datametica.starling.informatica.extractor.ImStageUtil$_getFields_closure11.doCall() is applicable for argument types: (groovy.util.slurpersupport.NodeChild) values: []
Possible solutions: doCall(groovy.util.slurpersupport.GPathResult, int), findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)




Aucun commentaire:

Enregistrer un commentaire