Java XML JAXB Unmarshaller unmarshal(JAXBContext context, Class clazz, String source)

Here you can find the source of unmarshal(JAXBContext context, Class clazz, String source)

Description

unmarshal

License

Apache License

Declaration

public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException 

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 java.io.StringReader;

public class Main {

    public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException {

        if (source == null) {
            return null;
        }//from w  w  w  .  j av a 2 s .  c o m

        StringReader reader = new StringReader(source);
        if (context == null) {
            context = JAXBContext.newInstance(clazz);
        }
        Unmarshaller un = context.createUnmarshaller();
        return (T) un.unmarshal(reader);
    }

    public static <T> T unmarshal(Class<T> clazz, String source) throws JAXBException {
        return unmarshal(null, clazz, source);
    }
}

Related

  1. unmarshal(InputStream in, Class... boundClasses)
  2. unmarshal(InputStream inputStream, Class entityClass)
  3. unmarshal(InputStream inputStream, Class type)
  4. unmarshal(InputStream is, Class clazz)
  5. unmarshal(InputStream stream, Class clazz)
  6. unmarshal(JAXBContext jaxbContext, XMLStreamReader xmlStreamReader)
  7. unmarshal(org.w3c.dom.Element elem, Class c)
  8. unmarshal(org.w3c.dom.Element elem, Class c)
  9. unmarshal(String b, Class implClass, Class... bc)