I have a JAX-RS servlet and I would like to return a JSON object for GET queries to the URL /upgrade/somePath but a String for GET queries to /upgrade/somePath?count=true. My problem is that this method cannot return two different types based on the query parameter. I tried to map a different method to a specific URL @Path("/upgrade/somePath?count=true") but Jersey was not happy to serve that.
@Path("upgrade")
public class UpgradeMock
{
@GET
@Path("somePath")
@Produces(MediaType.APPLICATION_JSON)
public UpgradePackageList getPackages(@QueryParam("count") Boolean count)
As far as I know you cannot achieve this using Jersey. If this way of working is a must (i.e. the specification) you should change your method to return a
Stringand take JSON serialization into your hands by invoking Jackson’s JSON serializer manually.