Could not find matching constructor help with API

Hello guys,

Well I have created some keywords, but I have faced a problem. I have created API method which fills a model.
for example method:
public Collateral_JsonModel callCollateral(Integer id)
and it is based on this:

@ToString
	class LoanCollateral_JsonModel {
		String id
		String typeid
		String address
            String typeName
	}

Well the problem is, when I call this method, I am not sure that it will give me a response, it can give me as a response: [] or some data [… , …, …, etc.]

When I try to execute this script:

def getIDFromDB = Methods.getLoanIDs('1122155')
println getIDFromDB
APIClass api = new APIClass()
for(int i = 0; i < getIDFromDB.size(); i++) {
	Collateral_JsonModel collateral = api.callCollateral(getIDFromDB[i])
}

if there is one id which gives me [] as response, it goes on an error:

Test Cases/New Test Case (3) FAILED.
Reason:
groovy.lang.GroovyRuntimeException: Could not find matching constructor

How can I make so that, put some logic if an api will give me an empty response to avoid such a problem ?

Just check the size of the getIDFromDB[i] call:

def id = getIDFromDB[i]
if(id.size() > 0) {
    Collateral_JsonModel collateral = api.callCollateral(id)
}
1 Like

Hello @Brandon_Hein, I have problem with calling a method. In getIDFromDB, I will always have some ID, but when I will just put this ID in the request, it can give me response [] or […].

Do you have access to the APIClass class? Can you share the method signature for callCollateral()?

1 Like

I have created a new method without using model, and now it works. I know that, that is not a perfect solution but :smiley:

@brithwulf temporary working solutions are permanent solutions :smile:

1 Like