I'd like to expose an interface through a web service. Instead of the "interface view" the actual implementation is exposed.
Example:
@XmlRootElement
public interface Foo extends Serializable {
String getId();
}
@XmlRootElement
public class MyFoo implements Foo {
private String id;
private String bar;
// Getter / Setter
}
@GET
@Path("myfoo")
@Produces(MediaType.APPLICATION_XML)
public MyFoo myFoo() {
MyFoo foo = new MyFoo();
foo.setId("myfoo");
foo.setBar("bar");
return foo;
}
This web service method will give the expected result like
<myFoo>
<bar>bar</bar>
<id>myfoo</id>
</myFoo>
The problem occurs when I try to expose the interface view only:
@GET
@Path("foo")
@Produces(MediaType.APPLICATION_XML)
public Foo foo() {
MyFoo myFoo = new MyFoo();
myFoo.setId("foo");
myFoo.setBar("bar");
Foo foo = myFoo;
return foo;
}
This will give the result:
<myFoo>
<bar>bar</bar>
<id>foo</id>
</myFoo>
But what I expect is a response like this:
<foo>
<id>foo</id>
</foo>
How am I able to achieve this?