Skip to content

Propagate CouchbaseCustomConverters bean into MappingConverter constructor #1850

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

Closed
mikereiche opened this issue Oct 13, 2023 · 9 comments · Fixed by #1885
Closed

Propagate CouchbaseCustomConverters bean into MappingConverter constructor #1850

mikereiche opened this issue Oct 13, 2023 · 9 comments · Fixed by #1885
Assignees

Comments

@mikereiche
Copy link
Collaborator

mikereiche commented Oct 13, 2023

AbstractCouchbaseConfiguration

@Bean
public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext,
		CustomConversions couchbaseCustomConversions) {
	MappingCouchbaseConverter converter = new MappingCouchbaseConverter(couchbaseMappingContext, typeKey(), couchbaseCustomConversions);
	converter.setCustomConversions(couchbaseCustomConversions);
	couchbaseMappingContext.setSimpleTypeHolder(couchbaseCustomConversions.getSimpleTypeHolder());
	return converter;
}
MappingCouchbaseConverter

public MappingCouchbaseConverter(
		final MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> appingContext,
		final String typeKey,
		final CustomConversions couchbaseCustomConversions) {
	super(new DefaultConversionService(), couchbaseCustomConversions);
	this.mappingContext = mappingContext;
...
	//CustomConversions customConversions = new CouchbaseCustomConversions(Collections.emptyList()); // DO NOT CREATE
AbstractCouchbaseConverter

protected CustomConversions conversions = null; // DO NOT CREATE new CouchbaseCustomConversions(Collections.emptyList());

...
protected AbstractCouchbaseConverter(final GenericConversionService conversionService, CustomConversions customConversions) {
	this.conversionService = conversionService;
	this.conversions = customConversions != null ? customConversions : null ; // null is error??
}
@bipoool
Copy link
Contributor

bipoool commented Nov 26, 2023

Hey @mikereiche can I work on this? Or on any other issue?

@mikereiche
Copy link
Collaborator Author

sure.

@bipoool
Copy link
Contributor

bipoool commented Dec 2, 2023

Please assign the issue to me.

@roman-sinyakov
Copy link

roman-sinyakov commented Dec 7, 2023

Is it gonna fix the problem after migration v4->5 when custom conversions in the overridden customConversions() method of the child class of AbstractCouchbaseConfiguration effectively hide embedded convertors?

@mikereiche
Copy link
Collaborator Author

Maybe - although I'm not aware of such a problem. Can you open a new issue for that?

@mikereiche
Copy link
Collaborator Author

I looked at this - and while it will make sense to pass couchbaseCustomConverters bean into the the constructor - where the constructor is called in AbstractCouchbaseConfiguration.mappingCouchbaseConverter(), couchbaseCustomConverters is applied after creation.

	@Bean
	public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingContext couchbaseMappingContext,
			CouchbaseCustomConversions couchbaseCustomConversions) {
		MappingCouchbaseConverter converter = new MappingCouchbaseConverter(couchbaseMappingContext, typeKey());
		converter.setCustomConversions(couchbaseCustomConversions); <--- applied here
		couchbaseMappingContext.setSimpleTypeHolder(couchbaseCustomConversions.getSimpleTypeHolder());
		return converter;
	}

@bipoool
Copy link
Contributor

bipoool commented Dec 25, 2023

Yup, it's better to pass it in the constructor down to AbstractCouchbaseConverter's constructor.
Changes are done and will raise the PR after proper testing.

On a side note. Shouldn't we also change the documentation where we Configuring Multiple Buckets

Screenshot 2023-12-26 at 4 36 37 AM

As this example is using new MappingCouchbaseConverter() to create mappingConverter. Which will not have the couchbaseCustomConversions. And it won't be able to find converters for JsonNode and etc.

In my opinion, we should also give an example where we also set couchbaseCustomConversions in MappingCouchbaseConverter

Something like -

mappingCouchbaseConverter.setCustomConversions(couchbaseCustomConversions);
Or
MappingCouchbaseConverter mapper = context.getBean(MappingCouchbaseConverter.class);

@bipoool
Copy link
Contributor

bipoool commented Dec 26, 2023

Hey, @mikereiche raised a PR for these changes.
Please review this when ever you get some time.

@bipoool
Copy link
Contributor

bipoool commented Jan 9, 2024

Any Update here? @mikereiche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants