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:
be primitive type;
have constructor accepts single string argument;
have static method named valueof or fromstring accepts single string argument (see, example, integer.valueof(string) , java.util.uuid.fromstring(string));
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
be list, set or sortedset, t satisfies 2 or 3 above. resulting collection read-only.
Comments
Post a Comment