Here you can find the source of marshallJAXBElement(Class
public static <BoundType> JAXBElement<BoundType> marshallJAXBElement(Class<BoundType> declaredType, QName name, Class<?> scope, BoundType v)
//package com.java2s; //License from project: Open Source License import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.namespace.QName; public class Main { public static <ValueType, BoundType> JAXBElement<BoundType> marshallJAXBElement( Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, Class<BoundType> declaredType, QName name, Class<?> scope, ValueType v) { try {//w w w. java 2 s . co m if (v == null) { return null; } else { final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass); return new JAXBElement<BoundType>(name, declaredType, scope, xmlAdapter.marshal(v)); } } catch (Exception ex) { throw new RuntimeException(ex); } } public static <BoundType> JAXBElement<BoundType> marshallJAXBElement(Class<BoundType> declaredType, QName name, Class<?> scope, BoundType v) { if (v == null) { return null; } else { return new JAXBElement<BoundType>(name, declaredType, scope, v); } } public static <ValueType, BoundType> XmlAdapter<ValueType, BoundType> getXmlAdapter( Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass) { try { final XmlAdapter<ValueType, BoundType> xmlAdapter = xmlAdapterClass.newInstance(); return xmlAdapter; } catch (IllegalAccessException iaex) { throw new RuntimeException(iaex); } catch (InstantiationException iex) { throw new RuntimeException(iex); } } }