Mara
Mara

Reputation: 41

Jersey: It's possible get from ResourceInfo the Interfaces that getResourceClass() implements?

I'm using jax-rs with jersey, I implemented a ContainerRequestFilter, and I have annotated ResourceInfo object with @Context annotation. there is a way to have not only the class but also its implemented interfaces directly from ResourceInfo? Or there is another way to get these information?

Upvotes: 4

Views: 755

Answers (1)

Paul Samsotha
Paul Samsotha

Reputation: 209112

I'm assuming you mean if you have

@Path("...")
public class Resource implements IOne, ITwo {

you want to get IOne and ITwo. For this, just use Class#getInterfaces()

public Class<?>[] getInterfaces()

Determines the interfaces implemented by the class or interface represented by this object.


For anyone for which the above is still unclear, ResourceInfo#getResourceClass returns the Class object for the resource class. From the returned Class object, you can call getInterfaces()

Class<?>[] ifaces = resourceInfo.getResourceClass().getInterfaces();

Upvotes: 1

Related Questions