dozer

How to tell Dozer to use LinkedHashSet collection in destination field?

ぐ巨炮叔叔 提交于 2019-12-24 00:59:59
问题 In first class i have field: private Set<Country> countries; public Set<Country> getCountries() { return countries; } public void setCountries(Set<Country> countries) { this.countries = countries; } which will contain LinkedHashSet implementation. In second class i have identical declaration, but during mapping, Dozer creates HashSet implementation in destination class, which destroys the order of elements. How to tell Dozer to use LinkedHashSet in destination class? 回答1: When Dozer maps a

Dozer Mapping Class level is-accessible

走远了吗. 提交于 2019-12-23 20:37:33
问题 I am using dozer framework for cloning my objects. I want dozer framework to clone the data without using the getters and setters and for this I am setting the is-accessible property at the class level. But this does not seem to work. When I set is-accessible at field level it works fine. BeanMappingBuilder builder = new BeanMappingBuilder(){ @Override protected void configure() { mapping(type(A.class).accessible(true),type(A.class).accessible(true)).exclude("field1").exclude("field2"); } };

How to map a field with type as an abstract class with dozer?

随声附和 提交于 2019-12-23 13:15:38
问题 I have the following domain structure: abstract class Person { String name; //with getter and setter } class Employer extends Person {} class Employee extends Person {} class Contract { Person contractor; //with getter and setter } class PersonDTO implements Serializable { String name; String type; //type == 'Employee' or 'Employer' } class ContractDTO implements Serializable { PersonDTO contractor; } Now when I set up this following dozer mapping: <mapping> <class-a>Person</class-a> <class-b

Dozer throwing lazyInitializationException

心不动则不痛 提交于 2019-12-23 04:36:12
问题 I'm trying to map my POJO to a DTO. I do not have any custom field mappers as all my fields in my DTO are same as in my POJO. But my POJO has multiple level of mapping involved. My problem is when i'm trying to copy the contents of my POJO to the DTO, i'm getting LazyInitializationException. Here is the code where the exception is thrown. public TestInfoDTO startTest(long testId) { TestInfo info = testDAO.startTest(testId); Mapper mapper = new DozerBeanMapper(); try { // Exception thrown here

Java: Merge 2 “beans” to produce a new one

与世无争的帅哥 提交于 2019-12-23 03:24:10
问题 I need to take all the fields and collections from Bean1 and Bean2, sometimes apply some business logic, and produce Bean3 (all beans are hibernate/domain objects of the same type with a reasonably complex graph). Any thoughts on how to do this? Done something similar in the past? My ideas: Dozer (http://dozer.sourceforge.net/) BeanUtils (http://commons.apache.org/beanutils/) Handrolled solution A.N.Other cool solution? Any recommendations? 回答1: Dozer is a nice bean mapping tool. However, it

How to pass `this` to Dozer field mapping?

岁酱吖の 提交于 2019-12-22 13:51:49
问题 In my app I have Dozer mapping which looks like this: <mapping> <class-a>java.util.HashMap</class-a> <class-b>org.mycompany.TargetClass</class-b> <field custom-converter="org.example.MyConverter"> <a>this</a> <b>anotherField</b> </field> </mapping> MyConverter is an instance of ConfigurableCustomConverter : public class MyConverter implements ConfigurableCustomConverter { private String parameter; @Override public Object convert( Object existingDestinationFieldValue, Object sourceFieldValue,

GWT + entities + JPA + DTO + Dozer

谁都会走 提交于 2019-12-22 12:39:54
问题 I am wondering what is the best way to handle mapping of entity beans (JPA 2) to DTOs. Since you cannot use entity beans "directly" with GWT, you need to handle DTOs instead. I have several entities with various relationships (OneToOne, OneToMany, ManyToMany with a join table etc). Initially i started converting all entities to DTOs by hand with the help of a class MyEntityTransform.java with methods like : static final public CarBean persistant2Bean(CarPersist) { return new CarBean

DTO to Entity And Entity to DTO

好久不见. 提交于 2019-12-21 16:54:03
问题 We're to use DTO's to send data to and from the presentation layer. We have layers like: facade appService domain And We have use Dozer to help us convert entity to dto. But i have 2 question now: from entity to dto we can use dozer, but from dto to entity can we use dozer? If Yes, How? Where shoud i create entity? in facade or DTOAssembler? for example,I have to register a book. the book Entity look's like: Book{ public Book(BookNumber number,String name){ //make sure every book has a

Mapping deep properties with intermediate collections in dozer

随声附和 提交于 2019-12-21 02:35:09
问题 Suppose I have the following classes public class Baz { private List<Foo> foos = new ArrayList<Foo>(); } public class Foo { private String string; } public class Target { private List<String> fooStrings = new ArrayList<String>(); } Is there any mapping I can use to, given a Baz, map it to the target class and get a list of the strings contained within the foo's in Baz? The following mapping does not work <mapping> <class-a>Baz</class-a> <class-b>Target</class-b> <field> <a>foos.string</a> <b

How to get the parent base class object super.getClass()

这一生的挚爱 提交于 2019-12-17 06:49:20
问题 I have a little problem with Java (being a C++ programmer). I have 2 related classes: public class Patient() { ... } public class PatientPersistent extends Patient { ... public void foo() { System.out.println(super.getClass().toString()); } } This will output: class org.example.smartgwt.server.model.PatientPersistent Is there a way to get the parent class type? i.e. class org.example.smartgwt.server.model.Patient. This will allow me to generalize some methods which I need to implement in each