Java Utililty Methods XML JAXB Context

List of utility methods to do XML JAXB Context

Description

The list of methods to do XML JAXB Context are organized into topic(s).

Method

JAXBContextgetJaxbContext(Class... classes)
get Jaxb Context
try {
    return JAXBContext.newInstance(classes);
} catch (JAXBException e) {
    throw new RuntimeException(e.getMessage(), e);
JAXBContextgetJaxbContext(Class... classTypes)
Get
JAXBContext retObj = null;
String key = "";
for (Class classType : classTypes) {
    if (!"".equals(key)) {
        key += ";";
    key += classType.getName();
retObj = jaxbContextMap.get(key);
if (retObj == null) {
    retObj = JAXBContext.newInstance(classTypes);
    jaxbContextMap.put(key, retObj);
return retObj;
JAXBContextgetJAXBContext(Class clazz)
get JAXB Context
String clazzName = clazz.getName();
JAXBContext jx = jaxbContextHash.get(clazzName);
if (jx == null) {
    jx = JAXBContext.newInstance(clazz);
    jaxbContextHash.put(clazzName, jx);
return jx;
JAXBContextgetJAXBContext(Class clazz)
get JAXB Context
Map<String, JAXBContext> cache = threadLocal.get();
JAXBContext jc = cache.get(clazz.getName());
if (jc == null) {
    jc = JAXBContext.newInstance(clazz);
    cache.put(clazz.getName(), jc);
return jc;
JAXBContextgetJaxbContext(Class clazz)
get Jaxb Context
JAXBContext jaxbContext = jaxbMap.get(clazz);
if (jaxbContext == null) {
    try {
        jaxbContext = JAXBContext.newInstance(clazz);
        jaxbMap.putIfAbsent(clazz, jaxbContext);
    } catch (JAXBException ex) {
        throw new RuntimeException("Could not instantiate JAXBContext.", ex);
return jaxbContext;
JAXBContextgetJAXBContext(Class clazz)
get JAXB Context
if (CTX_CACHE.containsKey(clazz)) {
    return CTX_CACHE.get(clazz);
} else {
    JAXBContext ctx = JAXBContext.newInstance(clazz);
    CTX_CACHE.put(clazz, ctx);
    return ctx;
JAXBContextgetJAXBContext(Class objclass)
Serialise the object to an XML string
JAXBContext jaxbContext;
if (jaxbContentCache.containsKey(objclass.getName())) {
    jaxbContext = jaxbContentCache.get(objclass.getName());
} else {
    jaxbContext = JAXBContext.newInstance(objclass);
    jaxbContentCache.put(objclass.getName(), jaxbContext);
return jaxbContext;
...
JAXBContextgetJaxbContext(Class valueType)
get Jaxb Context
JAXBContext jaxbContext = JAXB_CONTEXTS.get(valueType.getPackage());
if (jaxbContext == null) {
    jaxbContext = JAXB_CONTEXTS.get(valueType);
if (jaxbContext == null) {
    try {
        jaxbContext = JAXBContext.newInstance(valueType.getPackage().getName());
    } catch (JAXBException e) {
...
JAXBContextgetJaxbContext(String contextPath)
Returns a JAXB context for the given context path.
JAXBContext ctx = (JAXBContext) JAXB_CONTEXT_MAP.get(contextPath);
if (ctx == null) {
    ctx = JAXBContext.newInstance(contextPath);
    JAXB_CONTEXT_MAP.put(contextPath, ctx);
return ctx;
JAXBContextgetJAXBContext(String contextPath)
get JAXB Context
if (contextCache.containsKey(contextPath)) {
    return contextCache.get(contextPath);
} else {
    final JAXBContext context = JAXBContext.newInstance(contextPath);
    contextCache.put(contextPath, context);
    return context;