- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
We have a service that sends HTTP requests via RestTemplate API. The body is in JSON data type. The serilization happens via Jackson and therefore via AbstractJackson2HttpMessageConverter. We also want to use the Json Views feature for internal purposes. It means, that when we're sending the HTTP request, we want to serilize only a handful of fields, not all of them.
In order to use Json Views, we need to create a custom Jackson's ObjectWriter:
ObjectWriter objectWriter = new ObjectMapper()
    .registerModule(new JavaTimeModule())
    .writerWithView(Masking.class);
Unfortunately, the AbstractJackson2HttpMessageConverter only accepts the ObjectMapper as a customization parameter. It does not accepts the ObjectWrtier, rather, it constructs it internally later here. Becuase of this, there is no clear way of customizing the Json View to be used.
I hope the explaination and requirement is clear enough.
P.S: Also, I'm not sure that the AbstractJackson2HttpMessageConverter should accept the ObjectWriter directly, maybe the view can be customized via a custom void setWritingView(Class<?> view) method, or something. I'm leaving this question open for discussion.