Java XML JAXB Serialize deserialize(Class clazz, String filename)

Here you can find the source of deserialize(Class clazz, String filename)

Description

deserialize

License

LGPL

Declaration

public static <T> T deserialize(Class<T> clazz, String filename) throws JAXBException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {
    public static <T> T deserialize(Class<T> clazz, String filename) throws JAXBException {
        File file = new File(filename);
        JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        T t = (T) jaxbUnmarshaller.unmarshal(file);
        return t;
    }//from  w w  w .ja  va  2  s  .  c  o  m
}

Related

  1. deSerialize(Class docClass, InputStream inputStream)
  2. deserialize(Element elmnt, Class cls)
  3. deserialize(File fXMLFilePath, Class cls)
  4. deserialize(final Class clazz, final String json)