You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mark Woon <mo...@helix.stanford.edu> on 2005/04/01 16:17:54 UTC

Problem with custom serializers and namespaces

Hi all...

I'm new to Axis, so please bear with me.  I'm trying to write my own 
custom serializer/deserializers, and I'd like to use a custom namespace 
to go along with my types.

My Serializer.serialize() looks something like this:

  public void serialize(QName qName, Attributes attributes, Object value,
                        SerializationContext context) throws IOException {

    AttributesImpl att = new AttributesImpl(attributes);
    att.addAttribute("http://foo", "test", "foo:test", "CDATA", "hello");
    context.startElement(qName, att);
    context.endElement();
  }


Which outputs the following:

    <multiRef id="id0" soapenc:root="0" 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
ns1:="hello" xsi:type="ns1:testType" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:ns1="http://foo"/>

Unfortunately, this doesn't quite work since when I'm deserializing, I'm 
looking for attribute "foo:test", not "ns1:test".  What I'd expect 
context.startElement(qName, att); above to output is something more like:

    <multiRef id="id0" soapenc:root="0" 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
foo:test="hello" xsi:type="foo:testType" 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:foo="http://foo"/>


Am I missing something?  Is there a special way to register namespace 
prefixes in Axis or should I be doing something else?


Thanks,
-Mark