Java XML JAXB Unserialize load(final String xml, final Class clazz)

Here you can find the source of load(final String xml, final Class clazz)

Description

load

License

Open Source License

Declaration

public static <T> T load(final String xml, final Class<T> clazz) throws JAXBException 

Method Source Code


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

import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class Main {
    public static <T> T load(final String xml, final Class<T> clazz) throws JAXBException {

        StringReader reader = new StringReader(xml);
        try {/*from   w  w  w  .  ja  va 2  s  .  c  om*/
            final JAXBContext context = JAXBContext.newInstance(clazz);
            final Unmarshaller um = context.createUnmarshaller();

            @SuppressWarnings("unchecked")
            final T resource = (T) um.unmarshal(reader);

            return resource;
        } // try

        finally {
            reader.close();
        } // finally
    }
}

Related

  1. inputStreamToObject(InputStream xml, Class clazz)
  2. inputStreamToObject(String xml, Class clazz, Class[] classes)
  3. load(Class clazz, InputStream is)
  4. load(Class clazz, InputStream is)
  5. load(File f, Class... args)
  6. load(InputStream input, Class type)
  7. loadObject(Class typeClass, URL path)
  8. loadObject(Path path, Class clazz)
  9. loadXML(Class type, File sourceFile)