Here you can find the source of castUnmarshalled(Object unmarshalled, Class
public static <T> T castUnmarshalled(Object unmarshalled, Class<T> clazz)
//package com.java2s; import javax.xml.bind.JAXBElement; public class Main { public static <T> T castUnmarshalled(Object unmarshalled, Class<T> clazz) { if (clazz.isInstance(unmarshalled)) { return clazz.cast(unmarshalled); } else if (unmarshalled instanceof JAXBElement) { return castUnmarshalled(((JAXBElement<?>) unmarshalled).getValue(), clazz); } else {//from w w w .j ava 2 s. c o m throw new ClassCastException("Unmarshalled object is neither a " + clazz.getName() + " nor a " + JAXBElement.class.getName() + ": classname = " + unmarshalled.getClass().getName()); } } }