Java XML JAXB Unmarshaller unmarshall(Class clazz, String string)

Here you can find the source of unmarshall(Class clazz, String string)

Description

unmarshall

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static <CLAZZ> CLAZZ unmarshall(Class<CLAZZ> clazz, String string) throws JAXBException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {
    @SuppressWarnings("unchecked")
    public static <CLAZZ> CLAZZ unmarshall(Class<CLAZZ> clazz, String string) throws JAXBException {
        JAXBContext context = JAXBContext.newInstance(clazz);
        Unmarshaller um = context.createUnmarshaller();
        return (CLAZZ) um.unmarshal(new StringReader(string));
    }/* w w w . jav a 2s.  com*/

    @SuppressWarnings("unchecked")
    public static <CLAZZ> CLAZZ unmarshall(Class<CLAZZ> clazz, File xml)
            throws JAXBException, FileNotFoundException {
        JAXBContext context = JAXBContext.newInstance(clazz);
        Unmarshaller um = context.createUnmarshaller();
        return (CLAZZ) um.unmarshal(new FileReader(xml));
    }
}

Related

  1. unmarshalFromReader(Reader reader, Class c)
  2. unmarshalFromString(Class clz, String input)
  3. unmarshalFromXml(Class clazz, String xml)
  4. unmarshalFromXml(final String xml, Class destinationClass)
  5. unmarshalInstance(final String data, final Class expectedType)
  6. unmarshall(Class c, Object o)
  7. unmarshall(Class cls, Element domRequest)
  8. unmarshall(InputStream is, Class clz)
  9. unmarshall(InputStream toUnmarshall, Class clazz)