Java XML JAXB Unserialize loadXml(File file, Class requireType)

Here you can find the source of loadXml(File file, Class requireType)

Description

load Xml

License

Open Source License

Declaration


public static <T> T loadXml(File file, Class<T> requireType) throws Exception 

Method Source Code


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

import java.io.File;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;

import javax.xml.bind.Unmarshaller;

public class Main {

    public static <T> T loadXml(File file, Class<T> requireType) throws Exception {
        JAXBContext context = JAXBContext.newInstance(requireType);
        Unmarshaller um = context.createUnmarshaller();
        return (T) um.unmarshal(file);
    }/*from ww  w  .  ja  v  a  2  s . c  o  m*/

    public static <T> T loadXml(InputStream stream, Class<T> requireType) throws Exception {
        JAXBContext context = JAXBContext.newInstance(requireType);
        Unmarshaller um = context.createUnmarshaller();
        return (T) um.unmarshal(stream);
    }
}

Related

  1. load(final String xml, final Class clazz)
  2. load(InputStream input, Class type)
  3. loadObject(Class typeClass, URL path)
  4. loadObject(Path path, Class clazz)
  5. loadXML(Class type, File sourceFile)
  6. loadXML(Object object, String fileNamePath)
  7. loadXMLFromString(Object object, String line)
  8. parse(final Class clazz, final InputStream inputStream)
  9. parseIsoDate(String lexicalDate)