How to use:
1 Configure as Spring bean:
See sample XML snapshot attached to post
You can use JPA EntityManager or HibernateTemplate.
2 Annotate your DTO as needed:
public class AccountDTO implements Serializable {
@EntityProperty("id")
protected Long id;
@EntityProperty("username")
protected String username;
@EntityProperty("password")
protected String password;
...
/**
* Enum
*/
@EntityProperty("area")
protected Area area = Area.GE;
...
/**
* Role which this account in.
* Reference field type can be List<String>, List<Long> or List<Integer>
*/
@ReferenceId(value = "roles", entity = Role.class)
protected Set<String> roles = new HashSet<String>();
...
/**
* Table 'user' reference
* Reference field type can be String, Long or Integer
*/
@ReferenceId("user")
protected Long userId;
...
/**
* 3 levels deep inside
*/
@EntityProperty(value = "user.contact.firstName", readOnly = true)
protected String userFirstName;
...
/**
* Mapping collection of another DTOs
*/
@Dto(value = "user.contact.foreignAccounts", dto = ForeignIdDTO.class, entity = ForeignId.class, readOnly = true)
protected List<ForeignIdDTO> foreignAccounts = new ArrayList<ForeignIdDTO>();
...
/**
* Single DTO
*/
@Dto(value = "user.contact", entity = Contact.class)
protected ContactDTO contact;
3 Some rules/interfaces must be followed
Your entity must implement org.u268.dtomanager.Persistent interface
4 Use in code to convert:
Product entity = new Product();
dtoManager.toEntity(entity, productDTO);
...
ProductDTO created =
dtoManager.newDTO(entity, ProductDTO.class);
...
dtoManager.newDTOList(asset.getEntries(), ProductAssetEntryDTO.class)
Here u may find sample Spring bean config for DtoManager