Last active
January 13, 2018 12:24
-
-
Save Sam-Kruglov/e9cc47f7b495f1fd564a1816f66af8f3 to your computer and use it in GitHub Desktop.
JsonFilter without links
This file contains 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
@RepositoryRestController | |
public class UserController { | |
private final UserRepository userRepository; | |
public UserController(final UserRepository userRepository) { | |
this.userRepository = userRepository; | |
} | |
@GetMapping(value = "users/{id}", params = "fields") | |
public ResponseEntity<MappingJacksonValue> getUser(@PathVariable("id") Long id, | |
@RequestParam("fields") String fields) { | |
MappingJacksonValue wrapper = new MappingJacksonValue(userRepository.findOne(id)); | |
wrapper.setFilters(new SimpleFilterProvider() | |
.addFilter("userFilter", | |
SimpleBeanPropertyFilter.filterOutAllExcept(fields.split(",")))); | |
return ResponseEntity.ok(wrapper); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment