Skip to content

Instantly share code, notes, and snippets.

@Sam-Kruglov
Last active January 13, 2018 12:24
Show Gist options
  • Save Sam-Kruglov/e9cc47f7b495f1fd564a1816f66af8f3 to your computer and use it in GitHub Desktop.
Save Sam-Kruglov/e9cc47f7b495f1fd564a1816f66af8f3 to your computer and use it in GitHub Desktop.
JsonFilter without links
@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