com.godmonth.util.dozer.DozerTransformer Maven / Gradle / Ivy
package com.godmonth.util.dozer;
import org.apache.commons.collections4.Transformer;
import org.apache.commons.lang3.StringUtils;
import org.dozer.Mapper;
public class DozerTransformer implements Transformer {
private Mapper mapper;
private Class clazz;
private final String mapId;
public DozerTransformer(Mapper mapper, Class clazz) {
this(mapper, clazz, null);
}
public DozerTransformer(Mapper mapper, Class clazz, String mapId) {
this.mapper = mapper;
this.clazz = clazz;
this.mapId = mapId;
}
public OUT transform(IN input) {
if (StringUtils.isNotBlank(mapId)) {
return mapper.map(input, clazz, mapId);
} else {
return mapper.map(input, clazz);
}
}
}