@GET @Produces({BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE}) public Response listAllResources() { RootRepresentation root = new RootRepresentation(REP_TYPE, uriInfo); for (TopLevelResource resource : resources) { root.addLink( new ResourceLink( toResourceName(resource.getResourceClass()), uriInfo.getAbsolutePathBuilder().path(resource.getResourceClass()).build(), resource.getResourceMediaType())); } String selected = SUB_XML_MEDIA_TYPE; for(MediaType mt : headers.getAcceptableMediaTypes()) { if(mt.isCompatible(MediaType.valueOf(SUB_JSON_MEDIA_TYPE))) { selected = SUB_JSON_MEDIA_TYPE; break; } } return Response.ok(root).type(selected).build(); }