Example usage for javax.xml.bind.annotation.adapters XmlAdapter unmarshal

List of usage examples for javax.xml.bind.annotation.adapters XmlAdapter unmarshal

Introduction

In this page you can find the example usage for javax.xml.bind.annotation.adapters XmlAdapter unmarshal.

Prototype

public abstract BoundType unmarshal(ValueType v) throws Exception;

Source Link

Document

Convert a value type to a bound type.

Usage

From source file:Main.java

public static <ValueType, BoundType> BoundType unmarshall(
        Class<? extends XmlAdapter<ValueType, BoundType>> xmlAdapterClass, ValueType v) {
    try {/*from  w w  w  .  jav  a 2  s. c  o  m*/
        final XmlAdapter<ValueType, BoundType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
        return xmlAdapter.unmarshal(v);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

public static <ValueType, BoundType> ValueType unmarshallJAXBElement(
        Class<? extends XmlAdapter<BoundType, ValueType>> xmlAdapterClass, JAXBElement<? extends BoundType> v) {
    try {//from  w w w  .  j a  v a  2 s .c o  m
        if (v == null) {
            return null;
        } else {
            final XmlAdapter<BoundType, ValueType> xmlAdapter = getXmlAdapter(xmlAdapterClass);
            return xmlAdapter.unmarshal(v.getValue());
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:net.firejack.platform.core.utils.Factory.java

private Object get(Object bean, String name, Class valueType) {
    try {//from w  w w  . ja v a  2  s. co  m
        Object value;
        try {
            value = getInstance().getProperty(bean, name);
        } catch (NoSuchMethodException e) {
            value = getInstance().getProperty(bean, fixPath(name));
        } catch (Exception e) {
            value = null;
        }

        if (!Hibernate.isInitialized(value))
            value = null;

        if (value != null && valueType != null && value.getClass() != valueType) {
            XmlAdapter adapter = adapters.get(valueType.getName() + value.getClass().getName());
            if (adapter != null)
                try {
                    return adapter.marshal(value);
                } catch (ClassCastException e) {
                    return adapter.unmarshal(value);
                }
        }

        return value;
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
    return null;
}