Last active
January 13, 2018 12:16
-
-
Save Sam-Kruglov/4ccd2623ad7887cfb3ef4673bd14a87c to your computer and use it in GitHub Desktop.
JsonFilter without links simple
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
@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