Here you can find the source of unmarshall(InputStream toUnmarshall, Class
Parameter | Description |
---|---|
T | the type of object being unmarshalled |
toUnmarshall | the String to unmarshall |
clazz | the class of the unMarshsalled object |
Parameter | Description |
---|---|
JAXBException | if there is an error unmarshalling the String |
@SuppressWarnings("unchecked") public static final <T> T unmarshall(InputStream toUnmarshall, Class<T> clazz) throws IOException
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import javax.xml.bind.JAXBContext; public class Main { /**/*from w w w . j ava 2s. co m*/ * UnMarshalls a String to the specidfied object type. <br/> * Example: <code> * Environment unmarshalled = JaxbUtil.<Environment>unmarshall(marshalled, Environment.class); * </code> * * @param <T> * the type of object being unmarshalled * @param toUnmarshall * the String to unmarshall * @param clazz * the class of the unMarshsalled object * @return the Object * @throws JAXBException * if there is an error unmarshalling the String */ @SuppressWarnings("unchecked") public static final <T> T unmarshall(InputStream toUnmarshall, Class<T> clazz) throws IOException { Object unmarshalled = null; try { JAXBContext ctx = JAXBContext.newInstance(clazz.getPackage().getName()); unmarshalled = ctx.createUnmarshaller().unmarshal(new InputStreamReader(toUnmarshall)); } catch (Exception e) { throw new RuntimeException(e); } return (T) unmarshalled; } }