Java XML JAXB Context getJAXBContext(Class objclass)

Here you can find the source of getJAXBContext(Class objclass)

Description

Serialise the object to an XML string

License

Open Source License

Parameter

Parameter Description
obj the object to be serialised
objclass the class of the object to be serialised

Exception

Parameter Description
JAXBException an exception

Return

an XML string representing the object, or null if the object couldn't be serialised

Declaration


static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException 

Method Source Code

//package com.java2s;
//  sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is

import java.util.HashMap;

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

public class Main {
    private static HashMap<String, JAXBContext> jaxbContentCache = new HashMap<String, JAXBContext>();

    /** Serialise the object to an XML string
     * @param obj the object to be serialised
     * @param objclass the class of the object to be serialised
     * @return an XML string representing the object, or null if the object couldn't be serialised
     * @throws JAXBException //  ww w . j av a2 s  . co m
     */

    static private JAXBContext getJAXBContext(Class<?> objclass) throws JAXBException {
        JAXBContext jaxbContext;
        if (jaxbContentCache.containsKey(objclass.getName())) {
            jaxbContext = jaxbContentCache.get(objclass.getName());
        } else {
            jaxbContext = JAXBContext.newInstance(objclass);
            jaxbContentCache.put(objclass.getName(), jaxbContext);
        }
        return jaxbContext;
    }
}

Related

  1. getJaxbContext(Class... classTypes)
  2. getJAXBContext(Class clazz)
  3. getJAXBContext(Class clazz)
  4. getJaxbContext(Class clazz)
  5. getJAXBContext(Class clazz)
  6. getJaxbContext(Class valueType)
  7. getJaxbContext(String contextPath)
  8. getJAXBContext(String contextPath)
  9. getJAXBContext(String namespaces)