users@jersey.java.net

[Jersey] Re: Catch marshaling errors and present in one go

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 26 Mar 2015 10:29:03 +0100

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 <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 <https://jersey.java.net/documentation/latest/user-guide.html#bean-validation>

HTH,

~Jakub

> On 26 Mar 2015, at 09:30, naresh <baliga_naresh_at_yahoo.com> 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.