Is there a way to use RESTful Jersey service interfaces without JAX-WS annotations in implementation-related interfaces?

I like Jersey, I really do, but I would rather use interfaces as return types for my resources instead of concrete classes. I followed the instructions below:

http://jaxb.java.net/guide/Mapping_interfaces.html

He showed how you can annotate an interface with an adapter for classes that implement interfaces so that JAXB can bind them.

On the 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 an interface that knows what implements it, which seems pretty ugly. Our code uses the DAO template with factory to abstract from the database we are using, so we can change it later if we need to. This cyclic dependency just seems to cause problems later.

I am also unhappy that I cannot use these interfaces with my GWT client that will use these web services. Since the annotation is related to javax.xml.bind, it is not compatible with the GWT compiler. My current workaround is a dedicated support desk interface with annotations.

So is there a better way to do this? Maybe using Provider to instantiate classes? Or some type of filter that can map interfaces to some type of factory that can provide an implementation?

Any help would be appreciated.

Thanks.

+4
source share

Source: https://habr.com/ru/post/1342339/


All Articles