Archive for December, 2008

JAXB Undocumented

December 5, 2008 Leave a comment

When marshalling (Java to XML), how to add multiple namespace declaration in xml.

1. OverrideĀ  NamespacePrefixMapper
2. Override getPreDeclaredNamespaceUris, getPreferredPrefix methods as per your conveninece.

As of today, I did not find the above tip in any document.

import com.sun.xml.bind.marshaller.NamespacePrefixMapper;

public class PrefixMapperImpl extends NamespacePrefixMapper {

public String[] getPreDeclaredNamespaceUris() {
String[] result = super.getPreDeclaredNamespaceUris();
result = new String[] { “” };
return result;

public String getPreferredPrefix(String namespaceUri, String suggestion,
boolean requirePrefix) {
String prefix = “xsi”;
if (“urn:something.request”
prefix = “prefix”;
return prefix;


Categories: Uncategorized