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

no.digipost.jakarta.xml.bind.adapter.NullPassthroughXmlAdapter Maven / Gradle / Ivy

The newest version!
package no.digipost.jakarta.xml.bind.adapter;

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

import java.util.function.Function;

/**
 * Base class for creating {@link XmlAdapter}s where {@code null} values
 * are passed through, and not evaluated by marshalling/unmarshalling logic.
 *
 * @see XmlAdapter
 */
public class NullPassthroughXmlAdapter extends XmlAdapter {

    private final Function marshal;
    private final Function unmarshal;

    public NullPassthroughXmlAdapter(Function marshal, Function unmarshal) {
        this.marshal = marshal;
        this.unmarshal = unmarshal;
    }

    @Override
    public final ValueType marshal(BoundType boundValue) {
        return boundValue != null ? marshal.apply(boundValue) : null;
    }

    @Override
    public final BoundType unmarshal(ValueType xmlValue) {
        return xmlValue != null ? unmarshal.apply(xmlValue) : null;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy