1

Using Spring 3, I have created a MarshallingView, with the following marshaller:

<bean name="xmlMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <property name="classesToBeBound">
        <list>
            <value>com.mydomain.xml.schema.Products</value>
        </list>
    </property>
    <property name="marshallerProperties">
        <map>
            <entry key="com.sun.xml.bind.namespacePrefixMapper">
                <bean class="com.mydomain.xml.MyNamespacePrefixMapper"/>
            </entry>
        </map>
    </property>
</bean>

The MyNamespacePrefixMapper is supposed to map the schema of the Products object (XJC generated) to the default namespace, but it doesn't because the Jaxb2Marshaller is creating a JAXBContext that contains two different namespace URIs. One is my schema, the other one is a blank string. The blank string overrides any attempt by me to assign a default namespace.

Anyone know why this blank string is there or how I can get rid of it?

rjsang
  • 1,757
  • 3
  • 16
  • 26

1 Answers1

1

You could try using MOXy JAXB. The Spring configuration remains the same, you simply need to add a jaxb.properties file in with your model classes with the following entry:

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

See JAXB marshalling problem - probably namespace related . Instead of using a NamespacePrefixMapper you can simply configure the namesapce prefixes on the standard @XmlSchema annotation:

@javax.xml.bind.annotation.XmlSchema( 
    namespace = "http://www.example.org", 
    xmlns = {
        @javax.xml.bind.annotation.XmlNs(prefix = "xsd", namespaceURI = "http://www.w3.org/2001/XMLSchema"),
    },
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
package example; 

This produces XML like:

<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://www.example.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Unfortunately my objects are XJC generated ones so I can't manually edit the annotations. I'm not sure I can put a properties file in the package with them either, or can that be anywhere on the classpath? – rjsang Aug 04 '10 at 08:41