Java XML JAXB Unmarshaller unmarshalFromXml(Class clazz, String xml)

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

Description

unmarshal From Xml

License

Apache License

Declaration

public static <T> T unmarshalFromXml(Class<T> clazz, String xml)
            throws JAXBException, UnsupportedEncodingException 

Method Source Code


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

import javax.xml.bind.*;

import java.io.ByteArrayInputStream;

import java.io.UnsupportedEncodingException;

public class Main {
    public static <T> T unmarshalFromXml(Class<T> clazz, String xml)
            throws JAXBException, UnsupportedEncodingException {
        final JAXBContext context = JAXBContext.newInstance(clazz);
        return unmarshalFromXml(context, clazz, xml);
    }//from   w  w  w . jav a  2  s  .c  o m

    @SuppressWarnings("unchecked")
    private static <T> T unmarshalFromXml(JAXBContext context, Class<T> clazz, String xml)
            throws JAXBException, UnsupportedEncodingException {
        final Unmarshaller um = context.createUnmarshaller();
        final ByteArrayInputStream input = new ByteArrayInputStream(xml.getBytes("UTF-8"));
        return (T) um.unmarshal(input);
    }
}

Related

  1. unmarshal(T entity)
  2. unmarshalByContent(Class clazz, String xmlContent)
  3. unmarshalDOMElement(byte[] input)
  4. unmarshalFromReader(Reader reader, Class c)
  5. unmarshalFromString(Class clz, String input)
  6. unmarshalFromXml(final String xml, Class destinationClass)
  7. unmarshalInstance(final String data, final Class expectedType)
  8. unmarshall(Class clazz, String string)
  9. unmarshall(Class c, Object o)