Hi,
I don't think bean validation will work, as it might never get to it due to the marshaling error encountered earlier on.
Basically need to get a callback on the marshaling exception, do something, but more importantly Jersey needs to keep going on and not stop on the first exception.
The MessageBodyWorkers may work.
What is the "normal" behavior in a REST POST or PUT though, where a user sends Strings that cannot marshal into the member variable data type in the POJO? Bail on the first bad marshal encountered? If that's normal, I guess that's what I might consider doing.
Sent from my T-Mobile 4G LTE Device
-------- Original message --------
From: "japod [via Jersey]" <ml-node+s576304n7583222h41_at_n2.nabble.com>
Date:03/26/2015 4:30 AM (GMT-06:00)
To: naresh <baliga_naresh_at_yahoo.com>
Cc:
Subject: Re: Catch marshaling errors and present in one go
Hi Naresh,
I am not sure i completely understand you use case.
However to better controll what happens when marshalling goes wrong
you should be always able to register your custom message body provider,
that would just delegate to the “original” one and process any exceptions being thrown.
Please see the following doc for some details:
https://jersey.java.net/documentation/latest/user-guide.html#d0e7605
In the above doc, marshalling is done within a resource method, but the same
pattern (MessageBodyWorkers usage) could be applied also within a custom
message body reader/writer.
Otherwise, the following doc discusses bean validation feature,
that you might want to consider to apply to your use case instead:
https://jersey.java.net/documentation/latest/user-guide.html#bean-validation
HTH,
~Jakub
On 26 Mar 2015, at 09:30, naresh <[hidden email]> wrote:
Hi,
I'm using Jersey 2.17 and am using Jackson with JAXB annotations on my
representations.
These annotations are used for producing and consuming JSON as well as XML.
If a user POSTs a String to a data member (buried deep inside my
representation object) that is a Double, I wish to catch the resulting
marshal error and return a nicely formatted message.
I want to catch *all* such marshaling errors before presenting my error
response back, so that there is complete feedback to the user on what they
need to correct in their POST.
All I can do currently is map the resulting exception and present an error
for the first such encountered marshaling error.
--
View this message in context: http://jersey.576304.n2.nabble.com/Catch-marshaling-errors-and-present-in-one-go-tp7583221.html
Sent from the Jersey mailing list archive at Nabble.com.
If you reply to this email, your message will be added to the discussion below:
http://jersey.576304.n2.nabble.com/Catch-marshaling-errors-and-present-in-one-go-tp7583221p7583222.html
To unsubscribe from Catch marshaling errors and present in one go, click here.
NAML
--
View this message in context: http://jersey.576304.n2.nabble.com/Catch-marshaling-errors-and-present-in-one-go-tp7583221p7583223.html
Sent from the Jersey mailing list archive at Nabble.com.