I'm working on a spring based project and I’m looking if there is a clean way of mapping a request DTO with “type” field to an Entity to write to a mongodb, without using a bunch of if statements. For example the request DTO would look like:
AnimalRequestDTO.java
Public class AnimalRequestDTO {
private AnimalType animalType;
private String name;
private int age;
...
}
And I would like to map that request to an entity automatically, so if the AnimalType was AnimalType.Monkey, it would map to the MonkeyEntity.java class or if it was AnimalType.Horse it would map to HorseEntity.java.
I was wondering if there is a useful spring tool/design pattern around something like this?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire