我使用fromString方法创建了自己的类,我相信JAXB将使用它将参数值字符串转换为我的对象。然而,在这个fromString方法里面,我有一个try catch块,它会引发异常。如下所示。JAX-RS异常映射器不处理参数转换时引发的异常?
public class Animal{
public static Animal fromString(final String input){
try{
...
}catch(IllegalArgumentException ae){
throw new CannotConvertAnimalException(); //this is my custom exception
}
}
}
然后,我有如下所示的CannotConvertAnimalException一个映射:
@Component
@Provider
public class CannotConvertAnimalExceptionHandler implements ExceptionMapper<CannotConvertAnimalException>
的事情是,在我的资源的方法。我使用的数据类型动物
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response showAnimalInfo(Animal animal){....}
事实证明,当参数字符串,它是要转换为动物投CannotConvertAnimalException我custome例外映射器不处理它。它继续抛出ParamException.QueryParamException,并将其提供给我的QueryParamException处理程序来处理响应。
你们是否有任何想法如何使它在转换失败以及CannotConvertAnimalException被抛出时正确的映射器处理它?