Skip to content

Review HttpMessageConverters.Builder to improve readability of code using the API #35704

@wilkinsona

Description

@wilkinsona

The builder class has two types of methods. There are a number that have override semantics:

  • jsonMessageConverter(HttpMessageConverter<?>)
  • stringMessageConverter(HttpMessageConverter<?>)
  • xmlMessageConverter(HttpMessageConverter<?>)
  • etc

And one that is additive:

  • customMessageConverter(HttpMessageConverter<?>)

It's not clear from the method names that they have these different semantics. A contributing factor here is that the HttpMessageConverter contract doesn't use just the format (JSON, XML, etc) of the message, it also considers the type that's being read or written. That would suggest that it should be possible to register two JSON message converters that handle different types but doing so using jsonMessageConverter isn't possible and one or both of them must be registered using customMessageConverter instead.

After some discussion, @rstoyanchev suggested renaming the methods to be named set… for the overriding case and add… for the additive case. We also considered dropping Message for brevity:

  • setJsonConverter(HttpMessageConverter<?>)
  • setStringConverter(HttpMessageConverter<?>)
  • setXmlConverter(HttpMessageConverter<?>)
  • addCustomConverter(HttpMessageConverter<?>)

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions