i have class takes enum values male,female @post . when sent wrong value 'male' instead of 'male' shows me 400 bad request message in rest client : can not construct instance of constants.constants$genderenum string value 'male': value not 1 of declared enum instance names @ [source: org.apache.catalina.connector.coyoteinputstream@718a453d; line: 7, column: 23] (through reference chain: valueobjects.consumervalueobject["gender"])
my rest end point looks below :
@consumes("application/json") @produces("application/json") @post public response addconsumer(consumervalueobject consumervo) here consumervalueobject holds enum .
how supress error message in rest client? tried exceptionmapper did not help!i need supress message due security issues!
this jackson response either jsonparseexceptionmapper or jsonmappingexceptionmapper. these classes come dependency
<dependency> <groupid>com.fasterxml.jackson.jaxrs</groupid> <artifactid>jackson-jaxrs-json-provider</artifactid> <version>${2.x.version}</version> </dependency> whether have explicit dependency or have resteasy-jackson2-provider (which uses above under hood), mappers registered implicitly through classpath scanning. instance have empty application class.
@applicationpath("/") public class resteasyapplication extends application {} this cause disovery/registration through classpath scanning. if don't have either of dependencies, , if in wildfly, not sure how registered, what's happening.
you write/register own exceptionmappers jsonparseexception , jsonmappingexception
@provider public class jsonmappingexceptionmapper implements exceptionmapper<jsonmappingexception> { @override public response toresponse(jsonmappingexception e) { return response.status(response.status.bad_request).build(); } } but have tested, it's tossup 1 registered, yours or jackson's. mappers put set (so unordered), pushed map, 1 get's pushed in. order in pushed in said tossup.
i guess partial answer, have not been able find solution guaranteed use mapper, aside registering classes explicitly (ultimately disabling classpath scanning), hassle.
but fight has been narrowed down. try again more if chance later
update
so not solution, semi-proof-of-concept show how can use our exceptionmapper.
import org.jboss.resteasy.spi.resteasyproviderfactory; import com.fasterxml.jackson.databind.jsonmappingexception; import com.my.pkg.jsonmappingexceptionmapper; @path("/init") public class initresource { @get public response init() { resteasyproviderfactory factory = resteasyproviderfactory.getinstance(); factory.getexceptionmappers().put(jsonmappingexception.class, new jsonmappingexceptionmapper()); return response.ok("done!").build(); } } once hit init endpoint first time, our jsonmappingexcpetionmapper register, , override existing one, whether jackson's or ours.
of course not want real, it's showing how override mapper. thing can't figure out put code. i've tried servletcontextlistener, in application constructor, in feature low priority. can't figure out. none of above occur before resteasy its final registration.
Comments
Post a Comment