0

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?

Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
  • After a lot of debugging, I get the feeling the problem lies with the SavedSearch class. I've added in a constructor and getters and setters but get this error: Error invoking bsh method: eval public class SavedSearch { . . . '' : Method Invocation gson.toJson – Ilyas Patel Jun 28 '13 at 00:26

2 Answers2

0

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.

Ilyas Patel
  • 400
  • 2
  • 11
  • 27
0

If there's an exception thrown, then you'll get this error. Maybe 'savedSearch' had a marshalling error? Did you try running a unit test with this code?

alphaadidas
  • 332
  • 2
  • 6