Java XML JAXB Unmarshaller unmarshall(String file, Class desiredClass, Class context)

Here you can find the source of unmarshall(String file, Class desiredClass, Class context)

Description

unmarshall

License

Open Source License

Declaration

public static <T> T unmarshall(String file, Class<T> desiredClass, Class context) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;

import javax.xml.bind.Unmarshaller;
import java.io.File;

public class Main {
    public static <T> T unmarshall(String file, Class<T> desiredClass, Class context) throws Exception {
        JAXBContext ctx = JAXBContext.newInstance(context);
        Unmarshaller unMarshaller = ctx.createUnmarshaller();
        JAXBElement<T> object = (JAXBElement<T>) unMarshaller.unmarshal(new File(file));
        return object.getValue();
    }//  w w  w.j  a  va2 s .  co m
}

Related

  1. unmarshall(Class cls, Element domRequest)
  2. unmarshall(InputStream is, Class clz)
  3. unmarshall(InputStream toUnmarshall, Class clazz)
  4. unmarshall(JAXBContext c, Element e)
  5. unmarshall(String cntxtPkg, InputStream in)
  6. unmarshall(String xml, Class... classesToBeBound)
  7. unmarshall(String xml, Class clazz)
  8. unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
  9. unmarshaller(Class entityType, InputStream in)