Here you can find the source of fromXML(JAXBContext context, String requestXML)
Parameter | Description |
---|---|
context | A formerly initialized JAXB Context. |
An | XML representation of a previously marshaled Java object. |
Parameter | Description |
---|---|
JAXBException | On error. |
@SuppressWarnings("unchecked") public static <T> T fromXML(JAXBContext context, String requestXML) throws JAXBException
//package com.java2s; /*/*from www . jav a 2 s . c o m*/ * Copyright (C) 2010 - present, Laszlo Csontos * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { /** * Unmarshalls the specified XML document to a call request object. * * @param context A formerly initialized JAXB Context. * @param An XML representation of a previously marshaled Java object. * @return Unmarshaled Java object. * @throws JAXBException On error. */ @SuppressWarnings("unchecked") public static <T> T fromXML(JAXBContext context, String requestXML) throws JAXBException { // Convert String to Reader StringReader sr = new StringReader(requestXML); // Unmarshall object T result = null; Unmarshaller um = context.createUnmarshaller(); result = (T) um.unmarshal(sr); return result; } }