简体   繁体   中英

ClassNotFoundException while deserializing data

I'm serializing a map of a Class object and a list of Strings, which works quite well. However if I try to deserialize it, I'm getting a ClassNotFoundException. Here's the code:

Map<Class<? extends IDomain>, List<String>> mapPresetImport = (Map<Class<? extends IDomain>, List<String>>) ois.readObject();

What could have caused that exception?

Ok, I got it now. IDomain is accessible, but the classes that are serialized are not, because they are in another package which are not included in the class path.

As you mentioned in the comment that the classes which are serialized are not available in the runtime classpath, so that is resulting in the ClassNotFoundException .

Is there another way to deserialize that data without loading/looking for the class first?

No, this dependency is a must to have. You need to include the classes before deserializing the Objects (for getting no such exceptions). The deserialization mechanism used in Java will surely fail at the stage where it tries to locate the class(es) which is(are) being deserialized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM