Hi,

I have a JAX-RS web service which uses JAXB for binding. Everything is
ok, but currently I have a Flash client which is not ready to
understand neither namespaces nor prefixes at all. I have to clean the
output XML of namespaces and prefixes, included xmlns attributes, but
I would´nt like having to modify my xml schemas so I´m looking for a
solution on binding time.

My approach has been to extend JAXBElementProvider in order to wrap
the default XMLStreamWriter, CachingXmlEventWriter in this case. So I
have something like this:

public class MyCustomJAXBElementProvider extends JAXBElementProvider {

    @Override
    protected void marshalToWriter(Marshaller ms, Object obj,
            XMLStreamWriter writer, MediaType mt) throws Exception {
        CachingXmlEventWriterWrapper wrappedWriter = new
CachingXmlEventWriterWrapper(writer);
        super.marshalToWriter(ms, obj, wrappedWriter, mt);
    }

}

class CachingXmlEventWriterWrapper implements XMLStreamWriter {

     private XMLStreamWriter wrappedStreamWriter;

     public CachingXmlEventWriterWrapper(XMLStreamWriter wrappedStreamWriter) {
            this.wrappedStreamWriter = wrappedStreamWriter;

     }

    ............

}

The wrapper implementation tries to generate a "clean" XML
overwritting "setPrefix", "writeEmptyElement" and others methods  but
I didn´t get to remove the "xmlns" attributes. Any ideas?.

Thanks in advance.

Regards,

Juanjo.

Reply via email to