Thursday, 15 August 2013

JSON registerObjectMarshaller not applied

JSON registerObjectMarshaller not applied

I am trying to test custom JSON mappings in a spock unit test. For testing
purposes I picked the Exception object to map, but I've tried some others
as well with no success. Here's the test:
def "JSON converts complex data object using mapping"(){
when:
JSON.registerObjectMarshaller(Exception) { Exception ex ->
return [
message: ex.message
]
}
def converter = JSON(new Exception("test"))
//also tried
//def converter = new Exception("test") as JSON
then:
converter.toString() == '{"message":"test"}'
}
I get the following exception thrown when I run the test:
No signature of method: com.mydomain.grails.JsonResponseBuilderSpec.JSON()
is applicable for argument types: (java.lang.Exception) values:
[java.lang.Exception: test] Possible solutions: Spy(),
Spy(groovy.lang.Closure), Spy(java.lang.Class), Spy(java.util.Map),
wait(), Mock() groovy.lang.MissingMethodException: No signature of method:
com.mydomain.grails.JsonResponseBuilderSpec.JSON() is applicable for
argument types: (java.lang.Exception) values: [java.lang.Exception: test]
Possible solutions: Spy(), Spy(groovy.lang.Closure), Spy(java.lang.Class),
Spy(java.util.Map), wait(), Mock() at
com.mydomain.grails.JsonResponseBuilderSpec.JSON converts complex data
object using mapping(JsonResponseBuilderSpec.groovy:107)
any idea what could be wrong?

No comments:

Post a Comment