Hi Bruno,
The unmarshalling process from a JSON document to a JAXB object may  
result in syntactic character loss when the JAXB object is marshalled  
back to a JSON document (plus when unmarshalling any unknown JSON  
objects will be ignored and thus will not appear in the marshaled JSON  
document).
So it is not possible to guarantee the exact result as from Jersey, in  
terms of characters received. Your solution will not guarantee that  
either because a subsequent result in something different because  
something else might have changed the state of the resource).
Do you want to utilize the toString method for logging/debugging  
purposes? If so you can use the logging filter:
   
https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/client/filter/LoggingFilter.html
create an instance of LoggingFilter and add it to the filters of the  
WebResource you use to get the JAXB object. You can write your own  
filter to buffer the response entity as a String, by copying the code  
from the logging filter.
Paul.
On May 12, 2009, at 10:23 AM, Bruno Vernay wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>