dozer

Dozer 自定义Converter -- LocalDateTime to Date

Deadly 提交于 2019-11-30 08:21:36
Spring boot项目,使用dozer将Jpa Entity中的LocalDateTime属性转到DTO中对应的LocalDateTime属性中报错 java.lang.NoSuchMethodException: java.time.LocalDateTime.<init>() at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_51] at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[na:1.8.0_51] at org.dozer.factory.ConstructionStrategies$ByConstructor.newInstance(ConstructionStrategies.java:272) ~[dozer-5.5.1.jar:na] 将DTO中的LocalDateTime换成Date又报错 java.lang.NumberFormatException: For input string: "2015-10-17T17:55:12.091" 解决方法: 添加一个自定义Convert public class LocalDateTimeToDateDozerConverter extends

A dozer map exception related to Spring boot devtools

北慕城南 提交于 2019-11-30 04:06:35
问题 I have encountered a very strange exception, and I don't know how to find the reason. Business background: Add goods and meantime it's price list, a goods have 5 price for diff level user. In controller, first convert goodForm to goods by using dozer, then call goodsService to save goods. In goodsService after saving goods, traversal goods price list and populate goodsId to goods price, GoodsForm: @Mapping("priceList") List<GoodsPriceForm> goodsPriceFormList; Goods: List<GoodsPrice> priceList

Copying one class's fields into another class's identical fields

孤人 提交于 2019-11-29 19:17:32
问题 I have this question. But it will be difficult for me to explain as I don't know exact terms to use. Hope someone will understand. I'll try to discribe to the best i can. I feel like this is much related to parsing Say there are two classes. And in both classes I have some variables, say strings (just for simplicity, variable type can be any), which have similar names . Eg: class ClassA{ String x,y,z; } class ClassB{ String x,y,z; } Now, what i need is, i need to copy the value of one class's

How to use Dozer with Spring Boot?

大城市里の小女人 提交于 2019-11-29 17:57:46
问题 I am working on a Spring Boot project. I just have annotation configuration. I want to include dozer to transform Entities to DTO and DTO to Entities. I see in the dozer website, they explain i have to add the following configuration in spring xml configuration file. Since i have not xml file but annotation configuration Java class, i don't know how to translate this into Java Configuration class. <bean id="org.dozer.Mapper" class="org.dozer.DozerBeanMapper"> <property name="mappingFiles">

How can I tell Dozer to bypass mapping null or empty string values per field using the programming api?

走远了吗. 提交于 2019-11-29 11:28:57
The faq explains how to do this in XML. This shows how to do it per class using the API . The problem is you have to set it on on the class. What if I only want it on one field? Is this possible? You don't need converter. Dozer allows to do it easily: import static org.dozer.loader.api.TypeMappingOptions.mapNull; import static org.dozer.loader.api.TypeMappingOptions.mapEmptyString; ... public Mapper getMapper() { DozerBeanMapper mapper = new DozerBeanMapper(); mapper.addMapping(beanMappingBuilder()); return mapper; } private BeanMappingBuilder beanMappingBuilder() { return new

微服务应用大行其道,我提供一个dto和entity转换工具类,方便大家做转换,少写机械代码,多陪陪家人

ぐ巨炮叔叔 提交于 2019-11-29 07:22:48
微服务应用大行其道,我提供一个dto和entity转换工具类,方便大家做转换,少写机械代码,多陪陪家人。 该工具类主要是对dozer进行了封装,使用过程代码量极少,废话少说,贴代码了 import java.util.ArrayList; import java.util.List; import org.dozer.DozerBeanMapper; import org.dozer.Mapper; public class DtoEntityUtil { static Mapper mapper = new DozerBeanMapper(); public static <D,E> E trans(D t,Class<E> clazz){ if(t == null) return null; return mapper.map(t, clazz); } public static <D,E> List<E> trans(D[] ts,Class<E> clazz){ List<E> es = new ArrayList<E>(); if(ts == null) return es; for(D d:ts) { E e = (E)trans(d,clazz); if(e != null) es.add(e); } return es; } public static <D,E>

How to map collections in Dozer

岁酱吖の 提交于 2019-11-28 21:14:20
I'd like to do something like: ArrayList<CustomObject> objects = new ArrayList<CustomObject>(); ... DozerBeanMapper MAPPER = new DozerBeanMapper(); ... ArrayList<NewObject> newObjects = MAPPER.map(objects, ...); Assuming: <mapping> <class-a>com.me.CustomObject</class-a> <class-b>com.me.NewObject</class-b> <field> <a>id</a> <b>id2</b> </field> </mapping> I tried : ArrayList<NewObject> holder = new ArrayList<NewObject>(); MAPPER.map(objects, holder); but the holder object is empty. I also played with changing the second argument without any luck... Stephane Grenier To quote: "Nested collections

How can I tell Dozer to bypass mapping null or empty string values per field using the programming api?

拈花ヽ惹草 提交于 2019-11-28 04:31:38
问题 The faq explains how to do this in XML. This shows how to do it per class using the API. The problem is you have to set it on on the class. What if I only want it on one field? Is this possible? 回答1: You don't need converter. Dozer allows to do it easily: import static org.dozer.loader.api.TypeMappingOptions.mapNull; import static org.dozer.loader.api.TypeMappingOptions.mapEmptyString; ... public Mapper getMapper() { DozerBeanMapper mapper = new DozerBeanMapper(); mapper.addMapping

Prevent Dozer from triggering Hibernate lazy loading

烂漫一生 提交于 2019-11-27 18:24:44
I am using Spring transactions so the transaction is still active when POJO to DTO conversion occurs. I would like to prevent Dozer from triggering lazy loading, so that hidden sql queries never occur : all fetching has to be done explicitly via HQL (to get the best control on performances). Is it a good practice (I can't find it documented anywhere) ? How to do it safely ? I tried this before DTO conversion : PlatformTransactionManager tm = (PlatformTransactionManager) SingletonFactoryProvider.getSingletonFactory().getSingleton("transactionManager"); tm.commit(tm.getTransaction(new

How to map collections in Dozer

谁说我不能喝 提交于 2019-11-27 13:38:32
问题 I'd like to do something like: ArrayList<CustomObject> objects = new ArrayList<CustomObject>(); ... DozerBeanMapper MAPPER = new DozerBeanMapper(); ... ArrayList<NewObject> newObjects = MAPPER.map(objects, ...); Assuming: <mapping> <class-a>com.me.CustomObject</class-a> <class-b>com.me.NewObject</class-b> <field> <a>id</a> <b>id2</b> </field> </mapping> I tried : ArrayList<NewObject> holder = new ArrayList<NewObject>(); MAPPER.map(objects, holder); but the holder object is empty. I also