You can create an ObjectMapper with the JaxbAnnotationIntrospector. ObjectMapper has methods to enable you to (un)marshall to/from a string.
A good way of checking that this all works is to implement a proper equals method on your object, round trip the object, and check equality.
Brian
> On Apr 16, 2015, at 07:12, ax487 <ax487_at_gmx.de> wrote:
>
> 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