Thanks.I need to serialize collection of keys.
What do you think, is your variant with SerializedForm class with
writeReplace and readResolve is quite well? Is it provide serialization for
any type of Key? I can patch my Guice version and add this functionality.

  private static class SerializedForm implements Serializable {
    final Type type;
    final Class<? extends Annotation> annotationType;
    final Annotation annotationInstance;

    SerializedForm(Key<?> key) {
      this.type = key.getTypeLiteral().getType();
      this.annotationType = key.getAnnotationType();
      this.annotationInstance = key.getAnnotation();
    }

    final Object readResolve() {
      return annotationInstance != null ? Key.get(type, annotationInstance)
          : annotationType != null ? Key.get(type, annotationType) :
Key.get(type);
    }

    private static final long serialVersionUID = 0;
  }

  private void readObject(ObjectInputStream stream) throws
InvalidObjectException {
    throw new InvalidObjectException("Use SerializedForm");
  }

  /** @since 2.0 */
  protected final Object writeReplace() {
    return new SerializedForm(this);
  }

Aleksey.


2009/8/10 [email protected] <[email protected]>

>
> On Aug 10, 5:15 am, Aleksey Didik <[email protected]> wrote:
> > In my project I need to transfer Key<T> through net, so it must be
> > serializable.
> > I have found that snapshot20090512 have this functionality, but
> > snapshot20090706 already not.
> > Why possiblity to serialize Key<T> was exluded from Guice?
> > Will it be added later, in 2.1 version?
>
> We decided that serializability wasn't a very good idea for Keys. To
> work around this, implement the serialization contract manually in
> your classes that have a Key field.
>  http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
> >
>


-- 
Best regards,
Aleksey Didik

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to