Skip to content

Allow for Json View customization in AbstractJackson2HttpMessageConverter #34662

@mipo256

Description

@mipo256

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions