Java – is there any way to use the interface of Jersey restful service without jax-ws annotation in the interface reference implementation?
I like Jersey, I really do, but I prefer to use interfaces as the return type of my resources rather than specific classes I follow the instructions here:
http://jaxb.java.net/guide/Mapping_interfaces.html
It shows how to annotate interfaces for classes that implement interfaces using adapters so that JAXB can bind to them
From page:
@XmlJavaTypeAdapter(AbstractFooImpl.Adapter.class) interface IFoo { ... } abstract class AbstractFooImpl implements IFoo { ... static class Adapter extends XmlAdapter<AbstractFooImpl,IFoo> { IFoo unmarshal(AbstractFooImpl v) { return v; } AbstractFooImpl marshal(IFoo v) { return (AbstractFooImpl)v; } } }
I'm not too crazy about the interface and know what to implement it, which seems a little ugly Our code uses the Dao schema with factory to abstract the database we are using, so we can exchange it when we need it later This cyclical dependence seems to cause problems later
I'm also not satisfied that I can't use these interfaces for GWT clients that I will use these web services Because the comments are from javax xml. Bind, so it is incompatible with the GWT compiler My current solution is a special server interface with annotations
So is there a better way? Maybe use provider to instantiate the class? Or can a certain type of filter map an interface to a certain type of factory that can provide an implementation?
Any help will be greatly appreciated
thank you.
Solution
Eclipse link JAXB (Moxy) provides support for mapping interfaces (I am the technical director):
> http://bdoughan.blogspot.com/2010/07/moxy-jaxb-map-interfaces-to-xml.html
Moxy can be easily used with Jersey:
> http://bdoughan.blogspot.com/2010/08/creating-restful-web-service-part-35.html