Created
December 8, 2019 10:19
-
-
Save asouza/8bf5c7a2b1f48c4c04700ae5d7ca3c90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
Team team = new Team("instrutores"); | |
Cycle cycle = new Cycle("novo ciclo", LocalDate.now().minusDays(60), LocalDate.now()); | |
ArrayList<SupportStrategy> strategies = new ArrayList<>(); | |
strategies.add(new SupportStrategy("descricao")); | |
TeamCycle teamCycle = new TeamCycle(cycle, team, strategies); | |
System.out.println(DataView.of(teamCycle) | |
.add(TeamCycle :: getId) | |
.add(TeamCycle :: getDescription) | |
.add("cycleName",t -> t.getCycle().getTitle()) | |
.add("strategy",t -> t.getStrategies().iterator().next(),StrategyDTO :: new) | |
.addCollection("strategies",t -> t.getStrategies(),StrategyDTO :: new) | |
.build()); | |
System.out.println(DataView.of(cycle) | |
.add(Cycle :: getTitle) | |
.addDate("startDate",Cycle :: getStartDate , "dd/MM/yyyy") | |
.addFormatted("startDate",Cycle :: getStartDate , date -> date.format(DateTimeFormatter.ofPattern("dd MM"))) | |
.build()); | |
GoalProgressionUpdate update = new GoalProgressionUpdate(null,new BigDecimal("20"), "foi complicado"); | |
System.out.println(DataView.of(update) | |
.add(GoalProgressionUpdate :: getDescription) | |
.addPercentual("progresso",GoalProgressionUpdate :: getActualProgress) | |
.build()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A ideia é minimizar a necessidade de criação de DTOs(não é zerar) para serialização nos endpoints. Eu olhei o ModelMapper e MapStruct antes. Caso conheçam outros, me avisem!!! Eu queria que algo assim fosse nativo e super fácil, mas até que fiquei feliz com o resultado.
O resultado do build() é um Map<String,Object> que pode ser serializado para Json pelo jackson ou outra lib...