Search code examples
jmetergsonbeanshell

Getting typed variable declaration error in a JMeter bean shell script


I have this short script in a Bean Shell Post Processor. It uses the GSON library to parse JSON into a Bean. I'm now trying to convert back to JSON using the toJson method but receive this error:

Typed variable declaration : Method Invocation gson.toJson

Code:

import com.google.gson.Gson;

public class SavedSearch {
    public String id;
}

Gson gson = new Gson();
SavedSearch savedSearch = new SavedSearch();

String newJsonFile = gson.toJson(savedSearch);
vars.put("jobSavedResponse", newJson);

Any suggestions on how to fix this?


Solution

  • I never got to the bottom of the above issue but found another solution which is probably a better one. In JMeter, I added a BSF PostProcessor instead of a Bean shell script. I chose javascript (the lowercase version) as my language and wrote a short script to perform what I needed to do.