@JsonProperty("user_name")
private String name;
@JsonIgnore
private String name;
/////////////////////////////
@JsonIgnoreProperties({"name", "id"})
public class Team{
}
@JsonFilter("TeamFilter")
public class SomeBean {
}
@GetMapping("/{id}")
public MappingJacksonValue getTeam(@PathVariable long id) {
TeamDTO team = teamService.getTeamById(id);
if(team == null) {
throw new TeamNotFoundException("Team not found with id: " + id);
}
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(team);
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("name", "city");
FilterProvider filters = new SimpleFilterProvider().addFilter("TeamFilter", filter);
mappingJacksonValue.setFilters(filters);
return mappingJacksonValue;
}
@GetMapping("")
public MappingJacksonValue getAllTeams() {
List<TeamDTO> teams = teamService.getAllTeams();
if(teams.isEmpty()) {
throw new TeamNotFoundException("No teams found");
}
List<EntityModel<TeamDTO>> teamEntityModels = teams.stream()
.map(team -> EntityModel.of(team,
linkTo(methodOn(TeamController.class).getTeam(team.getId())).withSelfRel(),
linkTo(methodOn(TeamController.class).getAllTeams()).withRel("teams"),
linkTo(methodOn(TeamController.class).deleteTeam(team.getId())).withRel("delete"),
linkTo(methodOn(TeamController.class).updateTeam(team.getId(), team)).withRel("update"))
)
.toList();
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(CollectionModel.of(teamEntityModels,
linkTo(methodOn(TeamController.class).getAllTeams()).withSelfRel()));
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("name", "city");
FilterProvider filters = new SimpleFilterProvider().addFilter("TeamFilter", filter);
mappingJacksonValue.setFilters(filters);
return mappingJacksonValue;
}
다음과 같다면 잘따라온 것 이다.