Java XML JAXB Marshaller marshall(Class c, String xml)

Here you can find the source of marshall(Class c, String xml)

Description

marshall

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <T> T marshall(Class<T> c, String xml) 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 {
    @SuppressWarnings("unchecked")
    public static <T> T marshall(Class<T> c, String xml) throws JAXBException {
        T res;/*from w w w. ja  va 2 s. co m*/
        if (c == xml.getClass()) {
            res = (T) xml;
        } else {
            JAXBContext ctx = JAXBContext.newInstance(c);
            Unmarshaller unmarshaller = ctx.createUnmarshaller();
            res = (T) unmarshaller.unmarshal(new StringReader(xml));
        }
        return res;
    }
}

Related

  1. marshal(T bean, Class... bc)
  2. marshal(T clazz)
  3. marshal(T object)
  4. marshal(T t, Class entityClass)
  5. marshalAsString(Class clz, T marshalObj)
  6. marshall(final Object o, Class clazz)
  7. marshall(Object o)
  8. marshall(Object obj)
  9. marshall(Object obj, URL schemaURL, Class... classesToBeBound)