Open GoogleCodeExporter opened 9 years ago
Regarding 1)
Is Injector.injectMembers(Object) sufficient to you?
Original comment by sven.lin...@gmail.com
on 15 Apr 2008 at 4:12
Within the context of deserialization (java.io.Serializable.readObject()) there
is no
way to get a reference to the injector instance, is there?
Original comment by phjar...@gmail.com
on 15 Apr 2008 at 4:16
Regarding 2)
Letting your InvocationHandler, MethodInterceptor or whatever you use implement
java.io.Externalizable and delegate the serialization to the origin Object what
solve
this problem, as far as I see.
Original comment by sven.lin...@gmail.com
on 15 Apr 2008 at 4:21
Unfortunately I don't have control over the parent object (which would be the
HTTP
session being serialized). =(
Original comment by phjar...@gmail.com
on 2 Jun 2008 at 9:05
You need to hook into your session serialization mechanism, and make your
Injector available to the
deserializing code. If anyone in the user's community has an implementation,
please post it here for review.
Original comment by limpbizkit
on 3 Jun 2008 at 9:42
Been open for a couple years and no one's posted anything more. Guice already
provides all the necessary hooks for making this work, typically using
Injector.injectMembers.
Original comment by sberlin
on 19 Feb 2011 at 8:32
Just in case it's useful to other people (this issue is still one of the top
hits for a google search of "deserialize guice injected object"), here is one
possible solution..
In the class being deserialized, mark relevant injected objects as transient.
Then:
@Inject
private static Provider<MyClass> provider;
/**
* When deserializing this object, use Guice to create an instance rather than
* using the default behaviour of invoking Class.newInstance() which in turn
* invokes the no-args constructor. This ensures that any Guice configuration
* occurs, including both constructor and member injection.
*/
private Object readResolve() throws ObjectStreamException {
return provider.get();
}
and in a guice module, ensure the provider field is initialised via
requestStaticInjection(MyClass.class);
Original comment by simon.ki...@airnz.co.nz
on 18 Jul 2011 at 9:27
[deleted comment]
[deleted comment]
I've came to following solution; I'm new with Guice so maybe I've missed
something important.
I think that use of injector and method injection is justified in this case, as
this code is should be part of lower level infrastructure.
Original comment by fima.rot...@gmail.com
on 24 Apr 2014 at 1:21
Attachments:
Original issue reported on code.google.com by
phjar...@gmail.com
on 20 Dec 2007 at 10:45