Java tutorial
//package com.java2s; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.adapters.XmlAdapter; public class Main { public static <ValueType, BoundType> ValueType unmarshallJAXBElement( Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, JAXBElement<? extends BoundType> v) { try { if (v == null) { return null; } else { final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass); return xmlAdapter.unmarshal(v.getValue()); } } catch (Exception ex) { throw new RuntimeException(ex); } } public static <BoundType> BoundType unmarshallJAXBElement(JAXBElement<? extends BoundType> v) { if (v == null) { return null; } else { return v.getValue(); } } 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); } } }