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

spreadsheet.mapper.o2w.compose.converter.buildin.BeanUtilsConverter Maven / Gradle / Ivy

The newest version!
package spreadsheet.mapper.o2w.compose.converter.buildin;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.NestedNullException;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spreadsheet.mapper.model.core.Cell;
import spreadsheet.mapper.model.meta.FieldMeta;
import spreadsheet.mapper.o2w.compose.WorkbookComposeException;
import spreadsheet.mapper.o2w.compose.converter.Converter;
import spreadsheet.mapper.utils.FieldUtils;


/**
 * using {@link BeanUtils#getProperty(Object, String)}, this used as default converter
 * 

* Created by hanwen on 15-12-16. */ public class BeanUtilsConverter implements Converter { private static final Logger LOGGER = LoggerFactory.getLogger(BeanUtilsConverter.class); @Override public String getValue(T object, Cell cell, FieldMeta fieldMeta) { try { if (!lookup(object, fieldMeta)) { return null; } return BeanUtils.getProperty(object, fieldMeta.getName()); } catch (NestedNullException e) { LOGGER.debug("{} is null", fieldMeta.getName()); return null; } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); throw new WorkbookComposeException(e); } } private boolean lookup(T object, FieldMeta fieldMeta) { Class fieldType = FieldUtils.getFieldType(object.getClass(), fieldMeta.getName().split("\\.")); return fieldType != null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy