Java XML JAXB Unmarshaller castUnmarshalled(Object unmarshalled, Class clazz)

Here you can find the source of castUnmarshalled(Object unmarshalled, Class clazz)

Description

cast Unmarshalled

License

Open Source License

Declaration

public static <T> T castUnmarshalled(Object unmarshalled, Class<T> clazz) 

Method Source Code

//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());
        }
    }
}

Related

  1. closeUnmarshaller(Unmarshaller u)
  2. createUnmarshaller()
  3. createUnmarshaller()
  4. createUnmarshaller()