File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2638,6 +2638,25 @@ which allows rendering only a subset of all fields in an Object. To use it with
2638
2638
controller method. Use a composite interface if you need to activate multiple views.
2639
2639
====
2640
2640
2641
+ If you want to do the above programmatically, instead of declaring an `@JsonView` annotation,
2642
+ wrap the return value with `MappingJacksonValue` and use it to supply the serialization view:
2643
+
2644
+ [source,java,indent=0]
2645
+ [subs="verbatim,quotes"]
2646
+ ----
2647
+ @RestController
2648
+ public class UserController {
2649
+
2650
+ @GetMapping("/user")
2651
+ public MappingJacksonValue getUser() {
2652
+ User user = new User("eric", "7!jd#h23");
2653
+ MappingJacksonValue value = new MappingJacksonValue(user);
2654
+ value.setSerializationView(User.WithoutPasswordView.class);
2655
+ return value;
2656
+ }
2657
+ }
2658
+ ----
2659
+
2641
2660
For controllers relying on view resolution, simply add the serialization view class
2642
2661
to the model:
2643
2662
You can’t perform that action at this time.
0 commit comments