All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.protea.foundation.util.XmlUtil Maven / Gradle / Ivy

Go to download

Integrate compatible versions of many external systems to create a REST/HTTP server foundation

There is a newer version: 0.5.12
Show newest version
package cc.protea.foundation.util;

import java.io.ByteArrayInputStream;

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

public class XmlUtil {

	@SuppressWarnings("unchecked")
	public static  T fromXml(final String content, final Class valueType) {
		if (content == null || valueType == null) {
			return null;
		}
		try {
			JAXBContext context = JAXBContext.newInstance(valueType);
	        Unmarshaller un = context.createUnmarshaller();
	        ByteArrayInputStream is = new ByteArrayInputStream(content.getBytes());
	        return (T) un.unmarshal(is);
		} catch (JAXBException e) {
			return null;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy