Hi,
I am developing an http remote api on top of Jersey framework. My client
requires me to send an error code whenever a parameter is of invalid
type/format.
For example, I have the following uri:
remoteapi.com/accounts/get?accountId=<ID>
where the id param should be numeric. If client passed a non-numeric value
to to id, I will return an error wrapped in an xml. ex:
<result>
<type>FAIL</type>
<errorCode>12</errorCode>
</result>
Here, errorCode:12 means invalid id. There are a lot of other error codes
that my client requires me to send back, like invalid status id, account
type id, etc... each of them having their error code (I have no choice but
to follow the requirement).
I know there are many ways I can accomplish my client requirement like using
ExceptionMapper, or just declaring the param type String and validate it.
But I am just wondering if I can extend jersey framework and use my own
annotation.
Something like this:
@Path("accounts/get")
public Account getAccount(
@QueryParam("id")
@InvalidFormatError(12)
@RequiredParamError(21) Long id
) {
return accountService.getAccount(id);
}
This looks cleaner, but I do not know how possible. Any thoughts? Thank you
in advance.
--
View this message in context: http://jersey.576304.n2.nabble.com/Invalid-Parameter-Format-tp6698976p6698976.html
Sent from the Jersey mailing list archive at Nabble.com.