![JAR search and dependency download from the Maven repository](/logo.png)
cn.featherfly.conversion.string.bp.BeanPropertyFormatConvertor Maven / Gradle / Ivy
package cn.featherfly.conversion.string.bp;
import cn.featherfly.common.bean.BeanProperty;
import cn.featherfly.common.lang.ArrayUtils;
import cn.featherfly.conversion.annotation.Format;
import cn.featherfly.conversion.string.format.FormatConvertor;
import cn.featherfly.conversion.string.format.FormatType;
/**
*
* 格式化转换器
*
*
* @param 转换对象类型
* @author 钟冀
*/
public class BeanPropertyFormatConvertor extends BeanPropertyConvertor {
private FormatConvertor convertor;
/**
* @param convertor convertor
*/
public BeanPropertyFormatConvertor(FormatConvertor convertor) {
this.convertor = convertor;
}
/**
* {@inheritDoc}
*/
@Override
protected String doToString(T value, BeanProperty beanProperty) {
FormatType formatType = new FormatType<>(getSourceType());
Format format = beanProperty.getAnnotation(Format.class);
if (beanProperty != null && format != null) {
formatType.setFormat(format.format());
formatType.setFormats(ArrayUtils.toList(format.formats()));
}
return convertor.sourceToTarget(value, formatType);
}
/**
* {@inheritDoc}
*/
@Override
protected T doToObject(String value, BeanProperty beanProperty) {
FormatType formatType = new FormatType<>(getSourceType());
Format format = beanProperty.getAnnotation(Format.class);
if (beanProperty != null && format != null) {
formatType.setFormat(format.format());
formatType.setFormats(ArrayUtils.toList(format.formats()));
}
return convertor.targetToSource(value, formatType);
}
/**
* 返回convertor
*
* @return convertor
*/
public FormatConvertor getConvertor() {
return convertor;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy