ClassNotFoundException when using SerializationUtils.clone()…. here is a solution to the problem.
ClassNotFoundException when using SerializationUtils.clone().
org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException: com.anonymized.bean.Person
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:166)
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:193)
at org.apache.commons.lang.SerializationUtils.clone(SerializationUtils.java:81)
at com.anonymized.CallingClass.handleRequestInternal(CallingClass.java:45)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: com.anonymized.bean.Person
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
Truncated. see log file for complete stacktrace
The call that throws the exception.
Person copy = (Person) SerializationUtils.clone(PersonHolder.getPerson(request));
PersonHolder.getPerson(request) Returns
aPerson
Person
implementsSerializable
request
is an HttpServletRequest that has data that is passed to the method I tried to clonePerson
. It contains the data required by thegetPerson
method. I don’t think it has anything to do with my problem, but I’m just trying to figure out what it’s doing.commons-lang-2.4.jar
included in my project.- I’ve imported
the org.apache.commons.lang.SerializationUtils
andPerson
classes.
Any idea what I’m doing wrong here?
Solution
Try importing org.apache.commons.lang3.SerializationUtils.