Java tutorial
//package com.java2s; 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 { 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); } } }