Java XML JAXB Context fromXML(JAXBContext context, String requestXML)

Here you can find the source of fromXML(JAXBContext context, String requestXML)

Description

Unmarshalls the specified XML document to a call request object.

License

Open Source License

Parameter

Parameter Description
context A formerly initialized JAXB Context.
An XML representation of a previously marshaled Java object.

Exception

Parameter Description
JAXBException On error.

Return

Unmarshaled Java object.

Declaration

@SuppressWarnings("unchecked")
public static <T> T fromXML(JAXBContext context, String requestXML) throws JAXBException 

Method Source Code

//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;
    }
}

Related

  1. clearContextCache()
  2. createContext(final Class bind)
  3. createJaxbContextFor(Object obj, Class[] classes)
  4. createRIContext(Class clss[], String defaultNS)
  5. generateTemporarySchemaFile(JAXBContext context)
  6. getCachedContext(String pkg)
  7. getContext()
  8. getContext()