0
votes

I have a class with a method which returns XML. Along with this I have a Spock unit test. The test works fine in isolation ie if I do test-app :unit TestSpec.

However it throws an error -

Cannot cast object 'com.mypackage.SequencePartResponse@518a824' with class 'com.mypackage.SequencePartResponse' to class 'grails.converters.XML'

when I run ALL my tests (test-app :unit). I found a similar problem on stackOverflow (12098289) which suggested using 'addConvertors(offendingClassName)' to cure this but that isn't working with Spock. it just throws a method not found error.

Anyone any ideas how to sort this?

2

2 Answers

0
votes

Well I found a way to make it work .. Rather than rendering as XML in my controller - "render someObject as XML" , I do "render new XML(someObject)" .. Though if someone could explain what's going on i'd appreciate it

0
votes

I am not sure if this will help you but this is a worth noting point.

Suppose you have a class ClassA and it has ClassB object inside it.

ClassA{
 ClassB obj;
 String val;

}

And if you try to fetch object of class A by using Lazy fetching, then the converter tries to convert the object of the ClassB too, but since it does not have anything for ClassB due to LAZY fetching, it will not be able to convert the object properly and throws this error.

It will try to convert it like the following

{
   obj : {//It will not find this and throw an exception},
   val :  "" 
}

So try to fetch your Object by using EAGER fetch type.

Hope it may help, if you are doing something like this.