Skip to content

Instantly share code, notes, and snippets.

@Sam-Kruglov
Last active January 13, 2018 12:16
Show Gist options
  • Save Sam-Kruglov/4ccd2623ad7887cfb3ef4673bd14a87c to your computer and use it in GitHub Desktop.
Save Sam-Kruglov/4ccd2623ad7887cfb3ef4673bd14a87c to your computer and use it in GitHub Desktop.
JsonFilter without links simple
@RestController
public class UserController {
private final UserRepository userRepository;
public UserController(final UserRepository userRepository) {
this.userRepository = userRepository;
}
@GetMapping(value = "users/{id}")
public MappingJacksonValue getUser(@PathVariable("id") Long id,
@RequestParam(value = "fields") String fields) {
MappingJacksonValue wrapper = new MappingJacksonValue(userRepository.findOne(id));
wrapper.setFilters(new SimpleFilterProvider()
.addFilter("userFilter",
SimpleBeanPropertyFilter.filterOutAllExcept(fields.split(","))));
return wrapper;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment