jersey - Map JAX-RS @PathParam to POJO Constructor With Annotations -


i want create endpoint has pathparam automatically calls constructor of object injected, has constructor of string argument. spell out in code:

here resource

@get @path("/{apiversion}" + "/item") public response version(@pathparam("apiversion") apiversion apiversion) {     return response.ok().build(); } 

i want string automatically used in call apiversion constructor. in apiversion class

public apiversion(string apiversion) {    this.versionstring = apiversion; } 

is possible access annotations? not have access resourceconfig.

yes, possible, without annotations other @pathparam, example you've given should work as-is. see https://jersey.github.io/documentation/latest/jaxrs-resources.html#d0e2271 (emphasis mine) :

in general java type of method parameter may:

  1. be primitive type;

  2. have constructor accepts single string argument;

  3. have static method named valueof or fromstring accepts single string argument (see, example, integer.valueof(string) , java.util.uuid.fromstring(string));

  4. have registered implementation of javax.ws.rs.ext.paramconverterprovider jax-rs extension spi returns javax.ws.rs.ext.paramconverter instance capable of "from string" conversion type. or

  5. be list, set or sortedset, t satisfies 2 or 3 above. resulting collection read-only.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

What is happening when Matlab is starting a "parallel pool"? -