users@jersey.java.net

[Jersey] Re: JAXB and Jackson annotations together

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 4 Jul 2012 22:35:24 -0700

On Tue, Jul 3, 2012 at 8:01 AM, Brian Mulholland <blmulholland_at_gmail.com> wrote:
> I am trying to write a Jersey service (and test client) that consumes
> the same bean hierarchy as json or xml (users choice). I did json
> first using Jackson annotations, and it worked perfectly. I did XML
> next using JAXB annotations added onto the Jackson ones in the beans,
> again, worked perfectly.
>
> However, when both annotations exist, the JSON stuff fails. The
> request launches, but I get UnrecognizedPropertyException on the
> server. The message is "Unrecognized field <fieldName> (Class
> <myClass>), not marked as ignorable." The field it blows up on is an
> array of sub-beans, which again, works FINE when I run with Jackson
> annotations alone.
>
> Why does the presence of JAXB annotations throw everything wonky? And
> how can I make them coexist peacefully?

There are two basic possibilities -- either Jackson's combined
annotation introspector handling has an issue, or it is due to Jersey
configuration.
If you can reproduce the issue outside of Jersey with just Jackson
(configured to use both annotations), it would be easier to figured
out the problem.

One possible source of problems is that semantics of JAXB annotations
differs a bit from that of Jackson's native handling; especially with
Jackson versions prior to 1.9. This could cause problems when JAXB
annotations are only added on getter or setter, not both. But this is
just one possibility.

-+ Tatu +-