-
Notifications
You must be signed in to change notification settings - Fork 1.6k
GH-1129: Add JacksonMimeTypeModule #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes spring-projects#1129 Introduce a `JacksonMimeTypeModule` with a simple `MimeTypeSerializer` for the proper inter-platform `MimeType` objects serialization. Essentially we call its `toString()` which is enough to carry mime-type info over the network. Register this module in the `JacksonUtils.enhancedObjectMapper()` which is used from the `DefaultKafkaHeaderMapper`. Such a module can be registered as a bean in the application context and will be automatically discovered by Spring Boot auto-configuration for Jackson * Modify a `DefaultKafkaHeaderMapper` to not deal with `MimeType` directly any more since it is covered by the `JacksonMimeTypeModule` even if `MimeType` is a part of collection like it is in case of mapped HTTP headers. * Modify `DefaultKafkaHeaderMapperTests` to check that `MimeType` is properly serialized into its string representation even if it in the collection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one issue.
* target JSON as a plain string. | ||
*/ | ||
private static final class MimeTypeSerializer extends JsonSerializer<MimeType> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package-protected ctor needed to avoid synthesized ctor with extra arg.
* Document a `JacksonMimeTypeModule`
Travis (checkstyle). |
NPE in |
I wonder if the deserializer should now (2.3) always decode to String? |
No, that's OK. See my latest commit. The problem is that even if we serialize So, if another side is still Not perfect, but enough so far... Just some thoughts to share... |
This broke backwards compatibility; a 3.0 app can't talk to a 2.1 app because the MimeType is no longer a String. |
Fixes #1129
Introduce a
JacksonMimeTypeModule
with a simpleMimeTypeSerializer
for the proper inter-platform
MimeType
objects serialization.Essentially we call its
toString()
which is enough to carry mime-typeinfo over the network.
Register this module in the
JacksonUtils.enhancedObjectMapper()
whichis used from the
DefaultKafkaHeaderMapper
.Such a module can be registered as a bean in the application context
and will be automatically discovered by Spring Boot auto-configuration
for Jackson
DefaultKafkaHeaderMapper
to not deal withMimeType
directly any more since it is covered by the
JacksonMimeTypeModule
even if
MimeType
is a part of collection like it is in case ofmapped HTTP headers.
DefaultKafkaHeaderMapperTests
to check thatMimeType
isproperly serialized into its string representation even if it in the
collection