Skip to content

This library allows you to convert your entities to a selected DTO class in a very easy way.

License

Notifications You must be signed in to change notification settings

romantulchak/dto-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Information

This library allows you to convert your entities to a selected DTO class in a very easy way.

How to use:

  1. Download last version of Jar from Release page

  2. Create configuration file and paste code below

@Configuration
@ComponentScan("com.mapperDTO")
public class ApplicationConfig {
    @Bean
    public EntityMapper newEntityMapper(){
        return new EntityMapper();
    }
    @Bean
    public EntityMapperInvoker<Object, Object> newEntityMapperInvoker(){
        return new EntityMapperInvoker<>();
    }
}
  1. Autowire EntityMapperInvoker into your service
@Autowired
private EntityMapperInvoker<YourEntity, YourDTO> entityMapperInvoker;
  1. Mark the fields in the DTO that you want to be mapped using
@MapToDTO(mapClass = {View.TripView.class, View.SeatTripView.class})
private long id;

mapClass is needed to avoid loops that work like JsonView

  1. Mark the DTO class
@DTO
public class CityDTO {
//your code
}
  1. And in your method just add next line
return entityMapperInvoker.entityToDTO(entity object, DTO.class, mapClass from the annotation); 

DTO class must contain constructor without any arguments

If the DTO class contains fields of type DTO - these classes should also be marked as @DTO

Use the "associatedField" property in the @MapToDTO annotation if your variable in the DTO has a different name than in the Entity

About

This library allows you to convert your entities to a selected DTO class in a very easy way.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages