users@jersey.java.net

[Jersey] Re: How to test the JAXB mapping

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

Well, thanks for the suggestion. I guess that "com.fasterxml.jackson.*"
is used a a default backend then? I used a
"com.fasterxml.jackson.databind.ObjectMapper" to write an object, but
this does not seem to take into account that there might be XmlAdapters
for some special types. Can I get that to work as well?

ax487

On 16.04.2015 16:24, Van Klaveren, Brian N. wrote:
> 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