Here you can find the source of xmlToJavaBean(String xml, Class
Parameter | Description |
---|---|
xml | a parameter |
c | a parameter |
@SuppressWarnings("unchecked") public static <T> T xmlToJavaBean(String xml, Class<T> c)
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { /**/*w w w . j av a 2 s. c o m*/ * * @param xml * @param c * @return */ @SuppressWarnings("unchecked") public static <T> T xmlToJavaBean(String xml, Class<T> c) { if (xml.trim().isEmpty()) { return null; } T t = null; try { JAXBContext context = JAXBContext.newInstance(c); Unmarshaller unmarshaller = context.createUnmarshaller(); t = (T) unmarshaller.unmarshal(new StringReader(xml)); } catch (Exception e) { e.printStackTrace(); } return t; } }