Skip to content

GH-1879: Factories Now Configure (De)Serializers #1907

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

Merged
merged 2 commits into from
Aug 12, 2021

Conversation

garyrussell
Copy link
Contributor

Resolves #1879

It was not intuitive that configuration properties were not applied when
construcing (De)Serializers programmatically.

The producer and consumer factories now call the configure() method.
However, the JSON implementations cannot be configured with a mixture
of setters and configuration properties.

Resolves spring-projects#1879

It was not intuitive that configuration properties were not applied when
construcing (De)Serializers programmatically.

The producer and consumer factories now call the `configure()` method.
However, the JSON implementations cannot be configured with a mixture
of setters and configuration properties.
}

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
if (this.configured) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be better to throw an exception (or at least WARN) to let end-users to know that they are wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do that; because the supplier is called each time a new consumer is created. The default suppliers return the same instance each time.

I could add a DEBUG log; WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Then WARN anyway: people have to know that they are doing something wrong.
With debug it may slip out and then we will get some issue that they config doesn't work this or that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - warn would be too much noise - maybe I should use 2 flags, one for setters (and throw exception) and one for configAlreadyDone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, maybe just close this as won't fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be, but it will say you that there is something wrong with the app. Then you go to docs and JavaDocs and you see that you can't combine setters configuration with properties one.
Isn't the the reason why we use that Assert all around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is a single shared version is used and if we call configure() multiple times, even though the complete operation is idempotent, the configuration will be in an indeterminate state while configure() is running, and another thread might be using it to deserialize.
I therefore only want to run configure() once.

Hence my suggestion to use 2 flags instead of 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it working with two flags, please?
I would say the option to reject is not appropriate since such a feature have been asked already not one time...
Thanks
(or we just can go with your current solution without any warning or error!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on polishing it...

}

@Override
public void configure(Map<String, ?> configs, boolean isKey) {
if (this.configured) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DITTO

@artembilan artembilan merged commit 852c447 into spring-projects:main Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants