I am using org.apache.commons.lang.SerializationUtils, but I have an error. I am new to Java, if you need more information, please let me know the code:
Profile profile2 = new Profile();
profile2.setFileName(path);
profile2.setStatus("UPLOADED");
byte[] payload2 = SerializationUtils.serialize(profile2);
profile = (Profile) SerializationUtils.deserialize(payload2);
runtime error output:
org.apache.commons.lang.SerializationException: java.lang.ClassNotFoundException: com.xxx.xxx.Profile
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:166)
at org.apache.commons.lang.SerializationUtils.deserialize(SerializationUtils.java:193)
people say the profile is not in the classpath. if that were true, an error occurred in "new Profile ()". I'm right?
I just found a workaround:
profile = (EveSuccessCriteriaProfile) SerializationUtils.deserialize(payload2);
replaced by
InputStream fis = null;
fis = new ByteArrayInputStream(payload2);
ObjectInputStream o = new ObjectInputStream(fis);
profile = (Profile) o.readObject();
it works great
source
share