1

I'm trying to use jason-io to serialize/deserialize MyClass instances. The jason-io library has two classes, JsonWriter and JsonReader which respectively perform serialization and deserialization. Both operations are invoked from a Grails controller.

During serialization a JSON object containing, among other things, class names is created. Deserialization fails at Class.forName("...MyClass"). The class name is correct.

I've traced the problem and found that the class loader of MyClass is a (java.net) URLClassLoader, but the JsonReader class loader is a (org.codehaus.groovy.grails.cli.support) GrailsRootLoader. I don't know how to fix this, though.

Thanks

Eduardo
  • 1,235
  • 16
  • 27

1 Answers1

1

This may be linked to a known issue in groovy. The solution in that bug report is to specify the class loader:

def file = new File('thingy.txt')
file.withObjectInputStream(getClass().classLoader){ ois ->
    def yourObject = ois.readObject ( )
} 

The withObjectInputStream method is available in groovy on other classes too, for example I used this successfully with an instance of GZIPInputStream.

Dónal Boyle
  • 3,049
  • 2
  • 25
  • 40