java - JAX-RS exception mapper does not handle the exception that is thrown when doing parameter conversion? -
i created own class fromstring method believe jaxb use convert parameter value string object. however, inside fromstring method, have try catch block bubbles exception. following.
public class animal{     public static animal fromstring(final string input){           try{              ...          }catch(illegalargumentexception ae){              throw new cannotconvertanimalexception(); //this custom exception          }      } }   and have mapper cannotconvertanimalexception following:
@component @provider public class cannotconvertanimalexceptionhandler implements exceptionmapper<cannotconvertanimalexception>   the thing in resource method. use data type animal
@get @produces({mediatype.application_xml, mediatype.application_json}) public response showanimalinfo(animal animal){....}   it turns out when parameter string converted animal throws cannotconvertanimalexception custome exception mapper not handle it. goes on throw paramexception.queryparamexception instead , gives queryparamexception handler handle response.
do guys have idea how make when conversion goes bad, , when cannotconvertanimalexception gets thrown, correct mapper handles it?
ok found answer this. turns out whatever exception throw when trying convert string object wrapped inside queryparamexception , handled queryparamexception exceptionmapper (if have one). 1 way around identify exception wrapped queryparamexception , use kind of map match cause of queryparamexception correct handler
map<exception, exceptionmapper> mapper;   and
catch(exception e){     exmapper = mapper.get(exception.getcause); }   of course need load yor map right exception , mapper. having spring injects map variable.
Comments
Post a Comment