RE: [picocontainer-dev] Constructor Injection and Serialization Patterns

"Michael Rimov" <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Organization Centerline Computers, Inc
Message-ID <001e01c878ab$eb31a860$c194f920$@com>
Sorry for not getting it, but I don't think I understand how Objenesis would
help with this problem?

 

What I want is to be able to:

 

ObjectInputStream ois = new ObjectInputStream( /* some input stream */ );

Sample s = (Sample)ois.readObject();

 

/* And then a miracle occurs! */

 

assert s.getClassLoader() != null;

 

And somehow have Sample useful, even if the classloader specified in the
constructor would have to be transient. (Or just not saved via custom
serialization/externalization).  

 

So far, the only things I can think of are atatic containers and have class
Sample read its own dependencies during readObject(). which of course, breaks
everything in the Pico book in only one function. :-)

 

Does this clarify my problem?  I suspect this isn't really anything Pico can
solve per-se, rather a standard pattern for dealing with this problem would be a
good thing to document.

 
-Mike

 

 

From: Paul Hammant [mailto:[email protected]] 
Sent: Tuesday, February 26, 2008 9:35 AM
To: dev-qxt/[email protected]
Subject: Re: [picocontainer-dev] Constructor Injection and Serialization
Patterns

 

It could be that we leverage http://code.google.com/p/objenesis/ for a variation
of ConstructorInjection.

 

We would bring it in to the PicoContainer jar as per Paranamer with 'shade'

 

That way you can have your cake and eat it ? Or am I missing the problem here ?

 

- Paul

 

On Feb 26, 2008, at 8:42 AM, Michael Rimov wrote:





Hi All,

 

Pico was my first initiation into constructor injection and I've been an avid
fan after finding it.  However, I'm lacking a solution to a problem that I keep
encountering.

 

Given the sample class:

 

public class Sample implements Serializable {

      private ClassLoader cl;

 

      public Sample(ClassLoader classLoader) {

            cl = classLoader;

      }

}

 

The problem that I have is that since ClassLoader is not serializable, neither
is Sample.  If I make the classloader transient, then I deserialize a useless
object.

 

So far, the only solution I can see is to downgrade to setter injection.
(yuck!).

 

Has anybody come up with some sort of externalization pattern that they use in
practice that I can add to the "Best Practices" section for the Pico Docs?
Anything, especially in mind of usage in XStream, would be great :D

 

Thanks in advance!

                                                            -Mike
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.