users@jersey.java.net

[Jersey] How to reuse JAXB config in a toString method ?

From: Bruno Vernay <brunovern.a_at_gmail.com>
Date: Tue, 12 May 2009 10:23:51 +0200

Hi,

I use Jersey-client and JAXB to consume JSON services. I use
Jersey-server to test the client via JUnit (followed and simplified
this tip: http://blog.tmro.net/2009/03/unit-test-jax-rs-using-java-6-and-junit.html).

It went fine, just a little problem with JAXB and immutable objects.
Now I am really stuck with this problem:

I would like to implement a toString method for my object, that would
give the same exact result as Jersey. i.e. uses JAXB with the same
configuration and parameters as Jersey. But I didn't find any code
showing how to do it. I ended with this silly solution:

@Override
public String toString(){
    Client c = Client.create();
    WebResource r = c.resource("http://localhost:9998/myModule/meObject");
    return (String) r.get(String.class);
   //return "RefVO ("+this.maName + " ; "+this.versionId+" ;
"+this.lastModifiationDate.toString()+")";
}


Regards

-- 
Bruno VERNAY