tags:

views:

89

answers:

1

I saved a PublicKey instance in a file using ObjectOutputStream. This file is then stored inside a jar file which is then loaded by JBoss. I'm trying to read this file but it throws me an exception telling that it's not serializable. Here is the code :

InputStream input = KeyLoader.class.getClassLoader().getResourceAsStream(resource); ObjectInputStream objectInputStream = new ObjectInputStream(input); Object obj = objectInputStream.readObject(); Key output = (Key) obj; objectInputStream.close(); return output;

which throws me this exception An exception occurred: java.io.NotSerializableException

A: 

I'm not sure about serialization/deserialization from within a jar file, but without being able to see the rest of your code, I can say a few things:

  1. make sure that all of the classes that you are trying to serialize/deserialize implement Serializable.
  2. If you can't do number 1, then you might try getting an encoded form of the Key object, such as key.getEcnoded(), which would allow you to do input/output using the bytes of the key.

Edit: I'm not really familiar with JBoss, but maybe try using JBossObjectInputStream and JBossObjectOutputStream (org.jboss.serial.io). You will also have to add jboss-serialization.jar to your classpath. see link

also, I've never done this sort of thing before, but if you think the jar file is complicating things, but you should be able to use some of the classes in the java.util.jar package to simplify IO operations with jar files.

I hope this helps in some way.

YGL
The Key above is = java.security.Key interface which is serializable. The funny part is that I can load the same file (representing the Key object) within JBoss while the file is not inside JAR, but simply a file on the file system. Also I can read a serialized String object this way. This just don't work for the Key object. Any ideas ?
Tal