0

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
Jack Flamp
  • 1,223
  • 1
  • 16
  • 32
  • `@JsonIgnoreProperties` is Jackson and not directly related to JAX-RS. You can use Jackson with JAX-RS 1.x or 2.x. Show the whole stack trace please. – Paul Samsotha Jul 02 '19 at 07:37
  • 1
    You need to use the 1.x version of Jackson. You can tell by the package name `org.codehaus.jackson`. Jackson 1.x also has `@JsonIgnoreProperties` – Paul Samsotha Jul 02 '19 at 07:42
  • @PaulSamsotha I tried what you suggested [here](https://stackoverflow.com/a/30859992/3959856). But the annotation seems to be ignored. I am using the old codehaus package and same version as you suggested there. Did you ever find a reason/solution to this? – Jack Flamp Jul 02 '19 at 08:02
  • @PaulSamsotha [I found this though](https://developer.ibm.com/answers/questions/14353/jackson-annotations-ignored-in-liberty/) We are using Liberty when developing and Websphere 8.5.5 in production – Jack Flamp Jul 02 '19 at 08:17

0 Answers0