本文整理汇总了Java中org.dozer.DozerBeanMapper类的典型用法代码示例。如果您正苦于以下问题:Java DozerBeanMapper类的具体用法?Java DozerBeanMapper怎么用?Java DozerBeanMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DozerBeanMapper类属于org.dozer包,在下文中一共展示了DozerBeanMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConverterUtil
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* Constructor.
*
* @param dozerTypeConverter custom dozer converter for types
*/
public ConverterUtil(@Nonnull @NonNull final DozerTypeConverter dozerTypeConverter) {
final DozerBeanMapper dozerBeanMapper = new DozerBeanMapper();
final BeanMappingBuilder builder = new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(FieldDto.class, FieldInfo.class)
.fields("type", "type", FieldsMappingOptions.customConverterId("typeConverter"))
.fields("partition_key", "partitionKey", FieldsMappingOptions.copyByReference())
.fields("source_type", "sourceType", FieldsMappingOptions.copyByReference());
mapping(TableDto.class, TableInfo.class)
.fields("name", "name", FieldsMappingOptions.copyByReference());
mapping(DatabaseDto.class, DatabaseInfo.class)
.fields("name", "name", FieldsMappingOptions.copyByReference());
mapping(PartitionDto.class, PartitionInfo.class)
.fields("name", "name", FieldsMappingOptions.copyByReference());
mapping(AuditDto.class, AuditInfo.class);
mapping(StorageDto.class, StorageInfo.class);
}
};
dozerBeanMapper.addMapping(builder);
final Map<String, CustomConverter> customConverterMap = Maps.newHashMap();
customConverterMap.put("typeConverter", dozerTypeConverter);
dozerBeanMapper.setCustomConvertersWithId(customConverterMap);
this.mapper = dozerBeanMapper;
}
示例2: map
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
public static void map(final Object source, final Object destination, boolean ignoreNull) {
DozerBeanMapper mapper = new DozerBeanMapper();
if(ignoreNull) {
mapper.addMapping(new BeanMappingBuilder() {
protected void configure() {
mapping(source.getClass(), destination.getClass(), mapNull(false), mapEmptyString(true));
}
});
}
mapper.map(source, destination);
}
示例3: covertTweet
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
private Tweet covertTweet(org.springframework.social.twitter.api.Tweet tweet) {
Mapper mapper = new DozerBeanMapper();
Tweet tweetNew = mapper.map(tweet, Tweet.class);
tweetNew.setId(index++);
Entities entities = mapper.map(tweet.getEntities(), Entities.class);
// entities.setId(index++);
tweetNew.setEntities(entities);
TwitterProfile user = mapper.map(tweet.getUser(), TwitterProfile.class);
user.setId(index++);
tweetNew.setUser(user);
return tweetNew;
}
示例4: DozerTypeConverterLoader
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* Creates a <code>DozerTypeConverter</code> using the given
* {@link DozerBeanMapperConfiguration} configuration.
*
* @param camelContext the context to register the
* {@link DozerTypeConverter} in
*
* @param configuration dozer mapping bean configuration.
*/
public DozerTypeConverterLoader(CamelContext camelContext, DozerBeanMapperConfiguration configuration) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
ClassLoader appcl = camelContext.getApplicationContextClassLoader();
if (appcl != null) {
Thread.currentThread().setContextClassLoader(appcl);
}
log.info("Using DozerBeanMapperConfiguration: {}", configuration);
DozerBeanMapper mapper = createDozerBeanMapper(configuration);
this.camelContext = camelContext;
this.mapper = mapper;
this.configuration = configuration;
camelContext.addService(this);
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
示例5: createDozerBeanMapper
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* Creates a {@link DozerBeanMapper} from the given configuration.
*
* @param configuration the dozer bean mapper configuration.
* @return the created mapper
*/
public static DozerBeanMapper createDozerBeanMapper(DozerBeanMapperConfiguration configuration) {
DozerBeanMapper mapper;
if (configuration.getMappingFiles() != null) {
mapper = DozerComponent.createDozerBeanMapper(configuration.getMappingFiles());
} else {
mapper = DozerComponent.createDozerBeanMapper(Collections.<String>emptyList());
}
if (configuration.getCustomConverters() != null) {
mapper.setCustomConverters(configuration.getCustomConverters());
}
if (configuration.getEventListeners() != null) {
mapper.setEventListeners(configuration.getEventListeners());
}
if (configuration.getCustomConvertersWithId() != null) {
mapper.setCustomConvertersWithId(configuration.getCustomConvertersWithId());
}
if (configuration.getCustomFieldMapper() != null) {
mapper.setCustomFieldMapper(configuration.getCustomFieldMapper());
}
return mapper;
}
示例6: loadMappings
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
private List<ClassMap> loadMappings(CamelContext camelContext, String mapperId, DozerBeanMapper mapper) {
List<ClassMap> answer = new ArrayList<ClassMap>();
// load the class map using the class resolver so we can load from classpath in OSGi
MappingFileReader reader = new MappingFileReader(XMLParserFactory.getInstance());
List<String> mappingFiles = mapper.getMappingFiles();
if (mappingFiles == null) {
return Collections.emptyList();
}
for (String name : mappingFiles) {
URL url = loadMappingFile(camelContext.getClassResolver(), name);
if (url != null) {
MappingFileData data = reader.read(url);
answer.addAll(data.getClassMaps());
}
}
return answer;
}
示例7: setUp
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* Sets up the readers for the tests (all four constructor varieties are tested!).
*/
@Before
public void setUp() {
reader = new StringReader(CSV);
beanReader = new CsvDozerBeanReader(reader, PREFS);
tokenizer = new Tokenizer(reader, PREFS);
tokenizerBeanReader = new CsvDozerBeanReader(tokenizer, PREFS);
beanMapper = new DozerBeanMapper();
beanReaderWithMapper = new CsvDozerBeanReader(reader, PREFS, beanMapper);
configuredBeanMapper = new DozerBeanMapper(Arrays.asList("reference.xml"));
beanReaderWithConfiguredMapper = new CsvDozerBeanReader(reader, PREFS, configuredBeanMapper);
tokenizerBeanReaderWithMapper = new CsvDozerBeanReader(tokenizer, PREFS, beanMapper);
}
示例8: executeInternal
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
@Override
protected SavePropertyResult executeInternal(SaveProperty action, ExecutionContext context) throws ActionException {
DozerBeanMapper mapper = new DozerBeanMapper();
Properties property = mapper.map(action.getProperties(), Properties.class);
Contentholder originalProperty = contentholderDAOProvider.get().get(action.getProperties().getId());
property.setContentitems(originalProperty.getContentitems());
property.setTimeStamp(System.currentTimeMillis());
System.out.println("The property being saved = " + property.getId());
Users user = getUser();
System.out.println("The user =" + user);
property.setUser(user);
BaseWIPSvcHelper helper = new BaseWIPSvcHelper((Contentholder) property, contentholderDAOProvider.get(),
itemDAOProvider.get());
property = (Properties) helper.checkin();
postSaveOrUpdateproperties(property);
System.out.println("The property that got checkedin =" + property.getId());
PropertiesDTO pDTO = DozerBeanMapperSingletonWrapper.getInstance().map(property, PropertiesDTO.class);
return new SavePropertyResult(pDTO);
}
示例9: instance
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/** Returns the Singleton instance.
* @return the Singleton instance.
*/
public static DozerBeanMapper instance() {
if (c_instance == null) {
createInstance();
}
return c_instance;
}
示例10: sourceToDestinationMapping
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* @param source. The source object that needs to map to destination.
* @param destination. The destination object that needs to map from source.
* @return destination object
*/
public static Object sourceToDestinationMapping(Object source, Class destination) {
DozerBeanMapper mapper = DozerBeanMapperSingletonWrapper.instance();
Object destinationObj = mapper.map(source, destination);
return destinationObj;
}
示例11: mapper
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
@Bean
public DozerBeanMapper mapper() {
final DozerBeanMapper dozerBeanMapper = new DozerBeanMapper();
dozerBeanMapper.setMappingFiles(Collections.singletonList("dozerJdk8Converters.xml"));
dozerBeanMapper.addMapping(new StockToStockDtoMapping());
return dozerBeanMapper;
}
示例12: getDozer
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* @return the {@link DozerBeanMapper}.
*/
@Bean
public Mapper getDozer() {
List<String> beanMappings = new ArrayList<>();
beanMappings.add(DOZER_MAPPING_XML);
return new DozerBeanMapper(beanMappings);
}
示例13: testDozer
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
public Profiler testDozer(int invokeNum, String frameworkName) {
DozerBeanMapper mapper = new DozerBeanMapper();
long start = System.currentTimeMillis();
for (int i = 0; i < invokeNum; i++) {
Person7 p = getPerson();
PersonDto dto = mapper.map(p, PersonDto.class);
//System.out.println(dto);
}
return Profiler.apply(System.currentTimeMillis(), start)
.setFrameworkName(frameworkName);
}
示例14: useJEntityGraphDataMapper
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
/**
* Combines using an entityGraph for accessing data from a database with
* dozer mapping and returns a decoupled data object
*
* @param em
* entity manager for database access
* @param classTypeBE
* source object type
* @param classTypeDO
* destination object type
* @param entityGraphName
* name of the entity graph
* @param id
* identification number for accessed entity
* @return data object of type classTypeDO
*/
public <BE, DO> DO useJEntityGraphDataMapper(final EntityManager em, final Class<BE> classTypeBE,
final Class<DO> classTypeDO, final String entityGraphName, final int id) {
final BuildDozerMapping dozerMappingBuilder = new BuildDozerMapping();
final BuildEntityGraph entityGraphBuilder = new BuildEntityGraph();
BE businessEntity = null;
DO dataObject = null;
try {
dataObject = classTypeDO.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
@SuppressWarnings("unchecked")
final EntityGraph<BE> xmlGraph = (EntityGraph<BE>) entityGraphBuilder.generateEntityGraphXPath(em,
entityGraphName, classTypeBE);
final Map<String, Object> hints = new HashMap<String, Object>();
hints.put("javax.persistence.loadgraph", xmlGraph);
businessEntity = em.find(classTypeBE, id, hints);
final DozerBeanMapper mapper = dozerMappingBuilder.generateMappingRulesXPath(entityGraphName);
mapper.map(businessEntity, dataObject);
return dataObject;
}
示例15: registerClassMaps
import org.dozer.DozerBeanMapper; //导入依赖的package包/类
protected void registerClassMaps(TypeConverterRegistry registry, String dozerId, DozerBeanMapper dozer, List<ClassMap> all) {
DozerTypeConverter converter = new DozerTypeConverter(dozer);
for (ClassMap map : all) {
addDozerTypeConverter(registry, converter, dozerId, map.getSrcClassToMap(), map.getDestClassToMap());
// if not one way then add the other way around also
if (map.getType() != ONE_WAY) {
addDozerTypeConverter(registry, converter, dozerId, map.getDestClassToMap(), map.getSrcClassToMap());
}
}
}