All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.fasterxml.jackson.module.jaxb.AdapterConverter Maven / Gradle / Ivy

The newest version!
package org.testifyproject.testifyproject.fasterxml.jackson.module.jaxb;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.testifyproject.testifyproject.fasterxml.jackson.databind.JavaType;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.type.TypeFactory;
import org.testifyproject.testifyproject.fasterxml.jackson.databind.util.StdConverter;

public class AdapterConverter
    extends StdConverter
{
    protected final JavaType _inputType, _targetType;

    protected final XmlAdapter _adapter;
    
    protected final boolean _forSerialization;
    
    @SuppressWarnings("unchecked")
    public AdapterConverter(XmlAdapter adapter,
            JavaType inType, JavaType outType, boolean ser)
    {
        _adapter = (XmlAdapter) adapter;
        _inputType = inType;
        _targetType = outType;
        _forSerialization = ser;
    }
    
    @Override
    public Object convert(Object value)
    {
        try {
            if (_forSerialization) {
                return _adapter.marshal(value);
            }
            return _adapter.unmarshal(value);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return _inputType;
    }

    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return _targetType;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy