0

I have dived into the documentation, but only find circular references to the mechanical aspects of the use of webCleint, without any concrete examples… And nothing that merges it with the use of @JsonView.

I have a microservice that accepts a DTO from the client, performs basic validation, then wants to pass it on to another microservice. But, in passing it on, I want to strip out fields, per a JsonView.

Basic User DTO

    @JsonView({Views.Incoming.class,Views.Internal.class})
    private String email;
    @JsonView({Views.Incoming.class,Views.Internal.class})
    private String password;
    @JsonView(Views.Incoming.class)
    private String passwordCheck  //validated as matching in first service, not needed when handed off.

How do I a) actually build a webClient, make a request with it, and return a usable result, and b) give it my DTO filtered by @JsonView(Views.Internal.class)?

(The documentation about webClient itself is confusing, in that it suggests that a separate one is needed for each request (differentiating it from restTemplate), but the examples I have found instantiate one as static in the sercive class…)

Rick
  • 397
  • 3
  • 16
  • I think it is not possible as you would need to get access to objectWriter from objectMapper at the time of deserialization in webClient – Nick Dec 15 '21 at 12:47
  • Thanks @Nick. That would explain why I've not seen anything about using them together (despite it being such an obvious usecase). – Rick Dec 15 '21 at 13:05
  • you can try adding mixIns to objectMapper instead of working with views, it is also an option to add/ignore fields in mapping. See [link](https://www.baeldung.com/jackson-annotations#jackson-mixin-annotations) – Nick Dec 15 '21 at 13:44
  • Interesting theory, @Nick. Except that example shows how to exclude properties that are of a specific class. As I want to exclude one instance of `String` amongst several, that won't work either. – Rick Dec 15 '21 at 23:04

0 Answers0