本文整理汇总了Java中org.dozer.loader.api.BeanMappingBuilder类的典型用法代码示例。如果您正苦于以下问题:Java BeanMappingBuilder类的具体用法?Java BeanMappingBuilder怎么用?Java BeanMappingBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanMappingBuilder类属于org.dozer.loader.api包,在下文中一共展示了BeanMappingBuilder类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConverterUtil
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的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.loader.api.BeanMappingBuilder; //导入依赖的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: builder
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
@Override
public <SOURCE, DESTINATION> ReflectionModelTransformerBuilder<SOURCE, DESTINATION> builder() {
return sourceType -> destinationType -> excludeFieldNames -> () -> {
reflectionModelTransformer.addMapping(new BeanMappingBuilder() {
@Override
protected void configure() {
TypeMappingBuilder typeMappingBuilder = mapping(sourceType, destinationType,
oneWay(),
stopOnErrors());
excludeFieldNames.forEach(fieldName -> typeMappingBuilder.exclude(fieldName));
}
});
return source -> destination -> {
reflectionModelTransformer.map(source, destination);
return destination;
};
};
}
示例4: getRegisteredMappings
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
private List<BeanMappingBuilder> getRegisteredMappings() throws ReflectiveOperationException {
final ClassPathScanningCandidateComponentProvider scanner
= new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AssignableTypeFilter(BeanMappingBuilder.class));
final List<BeanMappingBuilder> customMapping = new ArrayList<>();
for (final BeanDefinition bd : scanner.findCandidateComponents(PACKAGE_TO_SCAN)) {
customMapping.add((BeanMappingBuilder) Class.forName(bd.getBeanClassName()).newInstance());
}
return customMapping;
}
示例5: addMapping
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
/**
* Registers Dozer <code>BeanMappingBuilder</code> in current mapper instance.
* This method should be called instead of direct <code>mapper.addMapping()</code> invocation for Camel
* being able to register given type conversion.
*
* @param beanMappingBuilder api-based mapping builder
*/
public void addMapping(BeanMappingBuilder beanMappingBuilder) {
if (mapper == null) {
log.warn("No mapper instance provided to " + this.getClass().getSimpleName()
+ ". Mapping has not been registered!");
return;
}
mapper.addMapping(beanMappingBuilder);
MappingFileData mappingFileData = beanMappingBuilder.build();
TypeConverterRegistry registry = camelContext.getTypeConverterRegistry();
List<ClassMap> classMaps = new ArrayList<ClassMap>();
classMaps.addAll(mappingFileData.getClassMaps());
registerClassMaps(registry, null, mapper, classMaps);
}
示例6: setUp
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
DozerBeanMapper mapper = createCleanMapper();
DozerTypeConverterLoader loader = new DozerTypeConverterLoader(context, mapper);
loader.addMapping(new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(CustomerDTO.class, Customer.class);
}
});
}
示例7: beanMappingBuilder
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
private BeanMappingBuilder beanMappingBuilder() {
return new BeanMappingBuilder() {
@Override
protected void configure() {
// add mappings here
}
};
}
示例8: init
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
@Before
public void init() throws CamundaRestException, InterruptedException {
processEngine = processEngineRule.getProcessEngine();
processEngine.getRuntimeService()
.startProcessInstanceByKey(
"Simple_Process"
, ImmutableMap.of("stringVar", "string", "otherVar", "other string")
);
Mockito.when(externalTaskRestService.fetchAndLock(Mockito.any(FetchExternalTasksDto.class))).then((invocation) -> {
FetchExternalTasksDto arg = invocation.getArgumentAt(0, FetchExternalTasksDto.class);
BeanMappingBuilder mappingBuilder = new BeanMappingBuilder() {
@Override
protected void configure() {
mapping(LockedExternalTask.class, LockedExternalTaskDto.class)
.fields("variables"
, new FieldDefinition("variables").accessible()
, FieldsMappingOptions.customConverter(VarConverter.class));
}
};
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.addMapping(mappingBuilder);
return arg.getTopics()
.stream()
.flatMap(topic -> processEngine.getExternalTaskService()
.fetchAndLock(arg.getMaxTasks(), arg.getWorkerId())
.topic(topic.getTopicName(), topic.getLockDuration())
.variables(new ArrayList<>(topic.getVariables()))
.execute()
.stream()
.map(task -> mapper.map(task, LockedExternalTaskDto.class))
)
.collect(Collectors.toList());
});
FetchExternalTasksDto.FetchExternalTaskTopicDto topicDto = new FetchExternalTasksDto.FetchExternalTaskTopicDto();
topicDto.setLockDuration(10000);
topicDto.setTopicName("simpleCommand");
topicDto.setVariables(Arrays.asList("stringVar", "otherVar"));
Mockito.when(manager.getExternalTaskTopics(Mockito.anyLong())).thenReturn(Collections.singletonList(topicDto));
Mockito.when(manager.toCommand(Mockito.any())).thenReturn(new Command());
processor = new ExternalTaskProcessor();
JavaUtils.setFieldWithoutCheckedException(
ReflectionUtils.findField(ExternalTaskProcessor.class, "externalTaskService")
, processor
, externalTaskRestService
);
JavaUtils.setFieldWithoutCheckedException(
ReflectionUtils.findField(ExternalTaskProcessor.class, "taskManager")
, processor
, manager
);
JavaUtils.setFieldWithoutCheckedException(
ReflectionUtils.findField(ExternalTaskProcessor.class, "taskSender")
, processor
, sender
);
}
示例9: setUp
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
final DozerConfig dozerConfiguration = new DozerConfig();
final BeanMappingBuilder mappingBuilder = dozerConfiguration.getBeanMappingBuilder();
mapper = dozerConfiguration.dozerBean(mappingBuilder);
}
示例10: addMappings
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
private static <E extends Entity, D extends DTO> void addMappings(final DozerBeanMapper mapper, final Class<E> entityClass, final Class<D> dtoClass,
IsMappingMode[] modes) {
for (final BeanMappingBuilder mapping : addDTOMapping(entityClass, dtoClass, modes)) {
mapper.addMapping(mapping);
}
}
示例11: dozerBean
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
/**
* Custom Mapper to Map from Domain-Object to DTO and from DTO to Entity-Object.
* Right now, it's only not possible to map from List<T> to List<U>, therefore you have
* to iterate through your list and map it in every iteration.
* Also we're not using DTO's, yet
*
* @param builder custom builder information
* @return Dozer Bean Mapper
*/
@Bean(name = "org.dozer.Mapper")
public DozerBeanMapper dozerBean(final BeanMappingBuilder builder) {
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.addMapping(builder);
return mapper;
}
示例12: addDTOMapping
import org.dozer.loader.api.BeanMappingBuilder; //导入依赖的package包/类
private static <E extends Entity, D extends DTO> List<BeanMappingBuilder> addDTOMapping(final Class<E> entityClass, final Class<D> dtoClass,
IsMappingMode[] modes) {
final ArrayList<BeanMappingBuilder> builders = new ArrayList<>();
// For each enum value, builds a custom mapping.
if (modes != null) {
for (final IsMappingMode mode : modes) {
final BeanMappingBuilder builder = new BeanMappingBuilder() {
@Override
protected void configure() {
// Basic mapping options.
final TypeMappingOption[] basicOptions = new TypeMappingOption[] {
TypeMappingOptions.oneWay(),
TypeMappingOptions.wildcard(true),
TypeMappingOptions.mapNull()
};
// Mapping builder.
// The Dozer map-id attribute is the getMapId() method of the enum value.
final TypeMappingBuilder tmb = mapping(entityClass, dtoClass, ArrayUtils.add(basicOptions, TypeMappingOptions.mapId(mode.getMapId())));
// Custom fields.
if (mode.getCustomFields() != null) {
for (final CustomMappingField custom : mode.getCustomFields()) {
final IsMappingMode customFieldMappingMode = custom.getMappingMode();
if (customFieldMappingMode != null) {
tmb.fields(custom.getEntityAttributeName(), custom.getDTOMapKey(), FieldsMappingOptions.useMapId(customFieldMappingMode.getMapId()));
} else {
tmb.fields(custom.getEntityAttributeName(), custom.getDTOMapKey());
}
}
}
// Excluded fields.
if (mode.getExcludedFields() != null) {
for (final MappingField excluded : mode.getExcludedFields()) {
tmb.exclude(excluded.getEntityAttributeName());
}
}
}
};
builders.add(builder);
}
}
return builders;
}