Getting an object from @PathParam

I am creating a RESTful service to access data.

So, I started writing this service, first created the ReadOnlyResource interface with the following code:

 public interface ReadOnlyResource<E, K> { Collection<E> getAll(); E getById(K id); } 

Where E is the return type and K is the key element.

So, if I implement using <Integer, Integer> , I will enter the key as t

 @GET @Path("/{id}") @Override public Integer getById(@PathParam("id") Integer id) { return null; } 

But when my key is more complicated, for example:

 public class ComplexKey { private String name; private int value; } 

How to do this so that I can use my interface?

Is there a way to enter both parameters and create a key with them?

EDIT: @QueryParam's solution does not help, because I try to get to / some name / some number and get an instance of ComplexKey that contains some name and some number values ​​from url.

+1
jersey jax-rs dropwizard
Apr 3 '17 at 7:21
source share
1 answer

what I'm trying to achieve is going to / some name / some number and getting an instance of ComplexKey that contains some name and some number values ​​from url

Use @BeanParam

 public class ComplexKey { @PathParam("name") private String name; @PathParam("value") private int value; // getters/setters } @Path("/{name}/{value}") getById(@BeanParam ComplexKey key) 
+3
Apr 03 '17 at 12:21
source share



All Articles