-
Notifications
You must be signed in to change notification settings - Fork 177
Override ObjectMapper in the DefaultDataConverter's payload coverter #410
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
Override ObjectMapper in the DefaultDataConverter's payload coverter #410
Conversation
Expose DataConverter.newBuilder() method to provide a way to customize e.g. ObjectMapper but not require clients to know the details how the default DataConverter is built.
Sorry for the delay. I don't like that the JSON specific configuration leaks into DataConverter class. But I also recognize the problem you are trying to solve. Let us think about the best solution. Keeping open for now. |
Thank you, @mfateev, that's definitely a fair issue. One simple way to tackle that could be to move the builder into the An alternative approach, although a bit more complex one, could be to add a "replace payload converter" method to the DataConverter.getDefaultInstance().withPayloadConverterOverride(JacksonJsonPayloadConverter(objectMapper)) |
I'm OK with |
Avoid direct dependency on DataConverter on specific PayloadConverter internals like ObjectMapper by supporting an option of merging custom PayloadConverters into the default PayloadConverters list in the DefaultDataConverter class.
@mfateev DataConverter converter =
DataConverter.newBuilder()
.setPayloadConverterOverrides(new JacksonJsonPayloadConverter(objectMapper))
.build(); |
Sorry, after looking at the PR I propose an alternative solution. I don't like that the My proposal is:
So the resulting code will be: DataConverter converter = new DefaultDataConverter()
.withPayloadConverterOverride(new JacksonJsonPayloadConverter(objectMapper)); |
temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java
Outdated
Show resolved
Hide resolved
temporal-sdk/src/main/java/io/temporal/common/converter/ProtobufJsonPayloadConverter.java
Outdated
Show resolved
Hide resolved
I've tried something like that. The trick is, as I've rolled back the DataConverter converter = new DefaultDataConverter(true, new JacksonJsonPayloadConverter(objectMapper)); Another alternative would be to create a factory method on the DataConverter converter = DefaultDataConverter.newInstanceWithDefaultPayloadConverters()
.withPayloadConverterOverride(new JacksonJsonPayloadConverter(objectMapper)); |
I see. Varags are error prone :(. And not providing a function for creation instead of a constructor was a mistake. I would name the function DefaultDataConverter.newDefaultInstance()
.withPayloadConverterOverride(new JacksonJsonPayloadConverter(objectMapper)); |
Also, replace by PayloadConverter.getEncodingType() instead of class.
Thanks! I've updated PR to use a factory method and a builder-like |
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.
Thanks a lot for the contribution!
Overview
Expose the
DataConverter.newBuilder()
method to provide a way to customize e.g.ObjectMapper
but not require clients to know the details of how the defaultDataConverter
is built.What was changed:
DataConverted.Builder
class is created to accept arbitraryObjectMapper
,JsonFormat.Printer
andJsonFormat.Parser
and build an instance ofDataConverter
that looks exactly likeDataConverter.getDefaultInstance()
except those custom mappers.ProtobufJsonPayloadConverter
is updated to use theprinter
provided via its constructor - before it used to always create a new printer viaJsonFormat.printer()
regardless of how it was configured.Why?
Right now in order to use a custom
ObjectMapper
clients have to directly instantiateDefaultDataConverter
and provide it with a proper list ofPayloadConvertes
. In order to keep this customDataConverter
as close to the default instance as possible clients should dowhich might be a bit more of knowledge of now default data converter is configured.
Instead, it would be great to only provide a custom
ObjectMapper
instance and otherwise build the same defaultDataConverter
.How has this been tested?
Existing and new unit tests.
Any docs updates needed?
Javadocs for new public methods were added.