Hello Frederic,
yes, there is better solution - all you need is set an init param and 
formatting will be done for you. See [1].
Pavel
[1] 
http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/core/util/FeaturesAndProperties.html#FEATURE_FORMATTED
On 01/21/2011 08:25 AM, Frederic Bergeron wrote:
> Hi,
>
> I would like to enable indentation when outputting XML with Jersey for debugging.  I've read how to do that here:
>
> http://markmail.org/message/lwazweptwslmshcw
>
> Here is my code that performs the same thing (or so I think):
>
> // Import declarations...
>
> public final class JAXBContextAdapter extends JAXBContext {
>
>      static {
>          System.out.println( "Loading JAXBContextAdapter" );
>      }
>
>      public JAXBContextAdapter( JAXBContext context ) {
>          this.context = context;
>      }
>
>      public Validator createValidator() throws JAXBException {
>          return( context.createValidator() );
>      }
>
>      public Unmarshaller createUnmarshaller() throws JAXBException {
>          return( context.createUnmarshaller() );
>      }
>
>      public Marshaller createMarshaller() throws JAXBException {
>          Marshaller m = context.createMarshaller();
>          m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
>          return( m );
>      }
>
>      private final JAXBContext context;
>
> }
>
>
> // Import declarations
>
> @Provider
> public class MyJAXBContextResolver implements ContextResolver<JAXBContext>  {
>
>      static {
>          System.out.println( "Loading MyJAXBContextResolver" );
>      }
>
>      public MyJAXBContextResolver() throws Exception {
>          this.types = new HashSet( Arrays.asList( cTypes ) );
>          this.context = new JAXBContextAdapter( JAXBContext.newInstance( cTypes ) );
>      }
>
>      public JAXBContext getContext( Class<?>  objectType ) {
>          return( ( types.contains( objectType ) ) ? context : null );
>      }
>
>      private final JAXBContext context;
>      private final Set<Class>  types;
>
>      private Class[] cTypes = { RegistryStore.class, Registry.class, ItemIdentifier.class, AccessPolicyType.class, ContentCollectionType.class,
>          IdentifierType.class, LangStringType.class, MetadataCollectionType.class, PropertyType.class, ProtocolImplementationDescriptionType.class,
>          ProtocolType.class, ResponsibleType.class, TargetType.class, ToAccessPolicyRelationshipType.class, ToCollectionRelationshipType.class,
>          ToContentCollectionRelationshipType.class, ToMetadataCollectionRelationshipType.class, ToTargetRelationshipType.class, VocabTermType.class
>      };
>
> }
>
> As you can see, I have inserted 2 static statements to output a trace to know whether my classes are loaded or not.  I don't see these traces on the log file so I assume that my classes are not loaded.
>
> What am I doing wrong?
>
> I also wonder if there is a better way to do that.  The proposed solution is 2 years old.  Maybe there is a newer and better way available now.
>
> Frederic Bergeron, Licef
>
>
>
>
>
>