1 package org.kuali.common.util.xml.jaxb.adapter; 2 3 import javax.xml.bind.annotation.adapters.XmlAdapter; 4 5 import com.google.common.base.Optional; 6 7 public class OmitOptionalAdapter<T> extends XmlAdapter<T, Optional<T>> { 8 9 @Override 10 public T marshal(Optional<T> optional) { 11 if (optional.isPresent()) { 12 return optional.get(); 13 } else { 14 return null; 15 } 16 } 17 18 @Override 19 public Optional<T> unmarshal(T value) { 20 if (value == null) { 21 return Optional.<T> absent(); 22 } else { 23 return Optional.<T> of(value); 24 } 25 } 26 27 }