cc.protea.foundation.util.XmlUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foundation Show documentation
Show all versions of foundation Show documentation
Integrate compatible versions of many external systems to create a REST/HTTP server foundation
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