List of usage examples for javax.xml.bind Unmarshaller unmarshal
public Object unmarshal(javax.xml.stream.XMLEventReader reader) throws JAXBException;
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T xml2Bean(String xml, Class<?> clazz) throws Exception { StringReader reader = null;//from w ww.jav a2 s . c om try { JAXBContext jc = JAXBContext.newInstance(new Class[] { clazz }); Unmarshaller m = jc.createUnmarshaller(); reader = new StringReader(xml); return (T) m.unmarshal(reader); } catch (Exception e) { } finally { close(reader); } return null; }
From source file:Main.java
public static Object importXmlJAXB(Class<?>[] clazz, Node node) throws JAXBException { long start = System.currentTimeMillis(); try {// w ww. j av a 2 s .com JAXBContext jc = getJAXBContext(clazz); Unmarshaller u = jc.createUnmarshaller(); return u.unmarshal(node); } catch (JAXBException ex) { throw ex; } finally { } }
From source file:Main.java
public static Object deserialize(Element elmnt, Class cls) throws JAXBException { final Unmarshaller um = JAXBContext.newInstance(cls).createUnmarshaller(); return um.unmarshal(elmnt); }
From source file:Main.java
@SuppressWarnings("unchecked") public static Object convertXmlStringToObject(String xml, Class clazz) { Object object = null;// w w w.j a va 2 s . c o m try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); StringReader xmlReader = new StringReader(xml); object = unmarshaller.unmarshal(xmlReader); } catch (JAXBException e) { e.printStackTrace(); } return object; }
From source file:Main.java
public static <T> T deserialize(Class<T> res, InputStream is) throws JAXBException { Unmarshaller u = CTX.createUnmarshaller(); u.setEventHandler(new DefaultValidationEventHandler()); return res.cast(u.unmarshal(is)); }
From source file:Main.java
public static Object xmlToJaxb(Class<?> xmlClass, InputStream is) throws JAXBException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<?> element = (JAXBElement<?>) unmarshaller.unmarshal(getReader(is)); return element.getValue(); }
From source file:eu.planets_project.tb.impl.serialization.JaxbUtil.java
public static <T> T unmarshallObjectViaJaxb(Class<T> objectClass, String serializedObject) throws Exception { JAXBContext context;//from ww w . j a va 2s .c o m try { context = JAXBContext.newInstance(objectClass); Unmarshaller um = context.createUnmarshaller(); return (T) um.unmarshal(new StringReader(serializedObject)); } catch (JAXBException e) { log.error("unmarshalWorkflowResult failed for objectClass" + objectClass + " with " + e); throw e; } }
From source file:gov.hhs.fha.nhinc.lift.proxy.util.ProxyUtil.java
public static Object unmarshal(org.w3c.dom.Element elem, Class<?> c) throws JAXBException { Object result = null;//w w w. j a v a 2 s. co m JAXBContext jc = JAXBContext.newInstance(c); Unmarshaller um = jc.createUnmarshaller(); result = um.unmarshal(elem); return result; }
From source file:gov.hhs.fha.nhinc.lift.proxy.util.ProxyUtil.java
public static Object unmarshalFromReader(Reader reader, Class<?> c) throws JAXBException { Object result = null;// w w w . j a v a 2 s .c om JAXBContext jc = JAXBContext.newInstance(c); Unmarshaller um = jc.createUnmarshaller(); result = um.unmarshal(reader); return result; }
From source file:demo.jaxrs.util.Marshal.java
public static <T> T unmarshal(Class<T> xmlType, String string) throws JAXBException { String namespace = ""; namespace = new String(string); System.out.println(namespace); namespace = namespace.replaceAll(" xmlns=\"http://ws.wso2.org/dataservice\"", ""); System.out.println(namespace); InputStream stream = Util.getInputStreamFromString(namespace); JAXBContext jaxbContext = JAXBContext.newInstance(xmlType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); T doc = (T) unmarshaller.unmarshal(stream); return doc;/*from w w w .j a v a2 s . c om*/ }