users@jersey.java.net

[Jersey] How to test the JAXB mapping

From: ax487 <ax487_at_gmx.de>
Date: Thu, 16 Apr 2015 16:11:20 +0200

Hello all,

I was wondering about test cases for my application and I am somewhat
uncertain regarding the JAXB "magic" that is happening going on behind
the scenes. If I write my own "toXML()" method I am able to look at the
code and see if I do everything correctly. However, with JAXB I
occasionally forget / mix up annotions, so the output does not look as
expected.

I would like to be able to test whether the mapping works correctly even
before writing an actual server test. To this end I would like to
marshal some data using Jersey to take a look at the resulting *JSON*
(not XML) output and maybe derive a unit test from it. Unfortunately I
could not find any code which actually does this in any of the examples
/ in the manual / on the internet. Could you provide me with a small
example showing the relevant classes within Jersey so that I can
reproduce the output for a specific annotated class?

ax487