Hi all,

*Question:*
Would you consider supporting classes annotated with JaxB (with annotation 
javax.xml.bind.annotation.XmlType) to be serializable by GWT service?

*Motivation:*
I work a lot with classes annotated with JaxB that are not 
java.io.Serializable and neither I can implement in them the 
com.google.gwt.user.client.rpc.IsSerializable interface.
This constrict our project to maintain an almost clone of the server data 
model and use Dozer to map jaxb-xml classes to gwt-IsSerializable ones.

*(Potential) Solution:*
Today I've tested hacking the 
com.google.gwt.user.rebind.rpc.SerializableTypeOracleBuilder (the one in 
GWT 2.7.0 sources) by changing isAutoSerializable() method into this:

 static boolean isAutoSerializable(JClassType type) {
    try {
      JClassType isSerializable = getIsSerializableMarkerInterface(type);
      JClassType serializable = getSerializableMarkerInterface(type);
      return type.isAssignableTo(isSerializable) || type.isAssignableTo(
serializable) || 
          type.isAnnotationPresent(XmlType.class);
    } catch (NotFoundException e) {
      return false;
    }
  }

where I have added to the OR condition the check to see if "type" is 
annotated with JaxB's @XmlType.

I've made some quick test, and with this hack I've successfully compiled a 
very large data set of JaxB annotated POJOs, and successfully exchanged in 
a GWT RPC service a couple of these object (in the next days I'll make more 
deep testing).

*Discussion:*
The solution is easy to apply, from my point of view the only negative 
impact is that it adds a new import to SerializableTypeOracleBuilder, but 
JSR 222 is integrated into Java SE since 1.6.

The contract on XmlType should be as restrictive as the one on 
Serializable, so if it is annotated correctly for JaxB, then it should 
serialize with GWT safely.

The above solution is partial, as to be fully compliant with JSR 222, it 
should also implement other JaxB annotations (among others @XmlAccessorType and 
@XmlTransient) but it could be initially implemented like this as 
Experimental feature enabled by a compiler option.



Could you please express your opinion and your level of harmony with this 
proposal? ;-)

If there is a bit of interest and nobody is against, I can open a issue and 
propose a patch, but it is 1 year I don't propose GWT patches and if 
someone with the hands in the code and gerrit could do it, I welcome him!


Thank you,
Cristiano









-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/96f1f18c-f50e-420a-b8a4-ba08861b423c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to