Java XML JAXB Unmarshaller unmarshaller(String xml, Class T)

Here you can find the source of unmarshaller(String xml, Class T)

Description

unmarshaller

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T unmarshaller(String xml, Class<?> T) 

Method Source Code


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

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import java.io.*;

public class Main {
    @SuppressWarnings("unchecked")
    public static <T> T unmarshaller(String xml, Class<?> T) {
        JAXBContext jc;/*from w  ww  .j  ava  2  s.c  om*/
        Unmarshaller unmarshaller;
        Object o = null;
        try {
            jc = JAXBContext.newInstance(T);
            unmarshaller = jc.createUnmarshaller();
            o = unmarshaller.unmarshal(new StreamSource(new StringReader(xml)));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return (T) o;
    }
}

Related

  1. unmarshall(String file, Class desiredClass, Class context)
  2. unmarshall(String xml, Class... classesToBeBound)
  3. unmarshall(String xml, Class clazz)
  4. unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
  5. unmarshaller(Class entityType, InputStream in)
  6. unmarshallJAXBElement(JAXBElement v)
  7. unMarshallRequest(String xmlString)
  8. unmarshallString(String str, Class c)
  9. unmarshallXml(final String string, final Class type)