Java XML JAXB Unmarshaller unmarshallString(String str, Class c)

Here you can find the source of unmarshallString(String str, Class c)

Description

unmarshall String

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T unmarshallString(String str, Class<T> c) throws IOException, JAXBException 

Method Source Code


//package com.java2s;
//License from project: GNU General Public License 

import java.io.ByteArrayInputStream;

import java.io.IOException;

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

import javax.xml.bind.Unmarshaller;

public class Main {
    private static JAXBContext jc = null;
    private static Unmarshaller um = null;

    @SuppressWarnings("unchecked")
    public static <T> T unmarshallString(String str, Class<T> c) throws IOException, JAXBException {
        initUnmarshaller(c);//from  ww  w.j  a v  a2s .  co m
        ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
        return (T) um.unmarshal(bis);
    }

    private static final <T> void initUnmarshaller(Class<T> c) throws JAXBException {
        jc = JAXBContext.newInstance(new Class[] { c });
        um = jc.createUnmarshaller();
    }
}

Related

  1. unmarshall(String xml, URL schemaURL, Class... classesToBeBound)
  2. unmarshaller(Class entityType, InputStream in)
  3. unmarshaller(String xml, Class T)
  4. unmarshallJAXBElement(JAXBElement v)
  5. unMarshallRequest(String xmlString)
  6. unmarshallXml(final String string, final Class type)
  7. unmarshallXMLtoObject(final byte[] xmlObject, final Class objectClass, final URL schemaURL)
  8. unmarshalObject(final InputStream input, final Class clazz)
  9. unmarshalPackage(InputStream pkgStream)