com.podio.item.map.converter.ExternalIdConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
The official Java wrapper for the Podio API
package com.podio.item.map.converter;
import java.beans.PropertyDescriptor;
import org.apache.commons.beanutils.ConvertUtils;
public class ExternalIdConverter {
private final PropertyDescriptor descriptor;
public ExternalIdConverter(PropertyDescriptor descriptor) {
super();
this.descriptor = descriptor;
}
public String fromModel(Object model) {
Object value;
try {
value = descriptor.getReadMethod().invoke(model);
} catch (Exception e) {
throw new RuntimeException("Unable to get external id");
}
if (value == null) {
return null;
}
return (String) ConvertUtils.convert(value, String.class);
}
public void toModel(String externalId, Object model) {
Object value = ConvertUtils.convert(externalId,
descriptor.getPropertyType());
try {
descriptor.getWriteMethod().invoke(model, value);
} catch (Exception e) {
throw new RuntimeException("Unable to set external id", e);
}
}
}