I am stuck with JAX-RS 1.1.0 for using REST and I am using javax.validation 1.1.0.FINAL.
When a consumer is sending an unknown property in the JSON they get an UnrecognizedPropertyException
with a 500 error code and a lot of yadi yadi..
I haven't found a way to catch this exception and send back something of my choosing (A 400 error e.g.)
The signature looks like this:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response storeDocument(DokumentData dokumentData)
Is there a way in this old version of JAX-RS to handle this exception nicely? In version 2.0 there is @JsonIgnoreProperties(ignoreUnknown = true)
but I can't use that.
Stacktrace:
[ERROR ] An unhandled exception occurred which will be propagated to the
container.
Unrecognized field "personnummer1" (Class
se.skandia.ad14.valueobjects.DokumentData), not marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6,
column: 23] (through reference chain:
se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
[ERROR ] SRVE0777E: Exception thrown by application class
'org.apache.wink.server.internal.RequestProcessor.handleRequest:195'
javax.servlet.ServletException:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized
field "personnummer1" (Class se.skandia.ad14.valueobjects.DokumentData), not
marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6,
column: 23] (through reference chain:
se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
at org.apache.wink.server.internal.RequestProcessor.handleRequest(RequestProcessor.java:195)
at [internal classes]
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "personnummer1" (Class
se.skandia.ad14.valueobjects.DokumentData), not marked as ignorable
at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@46611da2; line: 6, column: 23] (through reference chain: se.skandia.ad14.valueobjects.DokumentData["personnummer1"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
... 1 more