Java – ClassNotFoundException when using SerializationUtils.clone().

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 a Person
  • Person implements Serializable
  • request is an HttpServletRequest that has data that is passed to the method I tried to clone Person. It contains the data required by the getPerson 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 and Person classes.

Any idea what I’m doing wrong here?

Solution

Try importing org.apache.commons.lang3.SerializationUtils.

Related Problems and Solutions