Note that there are some explanatory texts on larger screens.

plurals
  1. POJava deserialization question
    text
    copied!<p>For reuse reasons I have wrapped my current serialization/deserialization services in an abstract generic class, which is compiled in a shared JAR across the project. I need to serialize objects to <code>String</code></p> <p>The class can be extended and a type can be specified for it in other JARs/WARs (yea, this is a web application).</p> <p>When I made my first deserialization tests from within the same WAR it all worked fine, but now that I moved the abstract class into another JAR I get a ClassNotFoundError when deserializing.</p> <p>The base class is structured as follows:</p> <pre><code>public abstract class ConverterBase&lt;T extends Serializable&gt; { public final Object getAsObject(String str) { //Use java.io serialization services from the base64 representation try { ByteArrayInputStream ba = new ByteArrayInputStream(decoder .decodeBuffer(str)); try { ObjectInputStream is = new ObjectInputStream(ba); try { Object ret = is.readObject(); return ret; } finally { is.close(); } } finally { ba.close(); } } catch (Throwable ex) { return null; } } public final String getAsString(Object obj) { //simply do the opposite } } </code></pre> <p>It is structured such a way in order to allow future changes impact all subclasses (ie. avoid base64, be more efficient...). For now, the <code>java.io</code> solution is a temporary implementation.</p> <p>Then I have the following inside the same WAR:</p> <pre><code>public class MyPojo implements Serializable { //Stuff } public final class MyPojoConverter extends ConverterBase&lt;MyPojo&gt; { } </code></pre> <p>The class that extends this one is in a different archive than the abstract class and is <strong>specialized</strong> on an type of that WAR.</p> <p>What could I do to avoid that error?</p> <p>Thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload