Right... That's the limitation of how the XmlJavaTypeAdapter stuff works. It's the concrete class that COMPLETELY drives the generated schema and what gets written to the wire. All the JAXB annotations go on that class, not the interface (other than the TypeAdapater annotation, although that could be put on the method/param instead).
That is actually why the Map example works. The "Map" interface really doesn't provide any useful information to create a nice schema. However, the concrete JAXB beans that the TypeAdapter will map it to does provide that ability. Thus, if you look at the schema that is generated for the map in my example, instead of generic <key> and <value> elements, it has nice descriptive <id> and <user> elements. The entry bean I created has the XmlElement annotations on it to make the schema nicer. Anyway, it does seem a bit backwords for the straight interface thing, but that's a limitation of how JAXB handles it. The TypeAdapters basically just provide a way for you to "intercept" the objects and map them to something JAXB will understand. JAXB then just uses those new objects for everything it deals with. Dan On Friday 29 February 2008, Ayush Gupta wrote: > Daniel, > > I tried this and am indeed able to use interfaces as parameters. > > However, I did encounter one problem: "The marshalling is being done > based on the concrete class of passed object and not based on the > interface itself" > > So, consider this example: > - Lets say that UserImpl has a few additional properties like userId > and userSalary (with getters/setters) which are not present in the > User Interface. > - When a client passes an instance of UserImpl to the service (as the > User interface) only name ought to be marshaled and not userId or > userSalary. > > The intent of wrapping UserImpl around an interface would be to > encapsulate some of the properties in UserImpl which are not pertinent > to User interface. Marshalling those "extra" properties defeats that > intent. > > I did discover that one way to hide userId and userSalary was to mark > the setters of those two in UserImpl with the XmlTransient annotation > but that does not feel so optimal. > > -ayush > > -----Original Message----- > From: Daniel Kulp [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 28, 2008 12:09 PM > To: [email protected] > Cc: [EMAIL PROTECTED] > Subject: Maps and Interfaces as params/returns sample.... > > > I just wanted to let everyone know that I've deployed a new CXF 2.1 > snapshot that has an updated java_first_jaxws sample that includes > using an interface and a Map object as parameters/returns to methods > on the interface. > > Since those have been common "issues" lately, I'd greatly appreciate > it if folks could give it a quick look and make any suggestions and > comments on how to make it even more useful. > > Download the latest from: > http://people.apache.org/repo/m2-snapshot-repository/org/apache/cxf/ap >ache-c xf/2.1-incubator-SNAPSHOT/ -- J. Daniel Kulp Principal Engineer, IONA [EMAIL PROTECTED] http://www.dankulp.com/blog
