Skip to content
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

Application custom conversions override spring-data-couchbase custom conversions since v5 #1876

Closed
roman-sinyakov opened this issue Dec 13, 2023 · 6 comments · Fixed by #1886
Assignees
Labels
status: feedback-provided Feedback has been provided type: enhancement A general enhancement

Comments

@roman-sinyakov
Copy link

roman-sinyakov commented Dec 13, 2023

We use Couchbase configuration with our own custom conversions declared like below since v4:

public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
    ...

    @Override
    @Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
    public CustomConversions customConversions () {
        return new CouchbaseCustomConversions(<our own convertors>);
    }

Method AbstractCouchbaseConfiguration.customConversions() is empty in v4:

public abstract class AbstractCouchbaseConfiguration {
        ...
	@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
	public CustomConversions customConversions() {
		return new CouchbaseCustomConversions(Collections.emptyList());
	}

After upgrade to v5 spring-data-couchbase owned convertors (e.g. StringToEnumConverterFactory) stopped working since this method AbstractCouchbaseConfiguration.customConversions() started declaring them since v5:

public abstract class AbstractCouchbaseConfiguration {
        ...
        public CustomConversions customConversions() {
		return customConversions(getCryptoManager(), getObjectMapper());
	}

I cannot see any way to have our own custom convertors and keep spring-data-couchbase custom convertors at the same time.
spring-data-couchbase 5.1.4
Please help

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 13, 2023
@roman-sinyakov roman-sinyakov changed the title Custom conversions overrride embedded conversions in spring-data-couchbase 5.1.4 Application custom conversions override spring-data-couchbase custom conversions since v5 Dec 13, 2023
@mikereiche
Copy link
Collaborator

Thanks for the description. I'll look into this.

@mikereiche
Copy link
Collaborator

mikereiche commented Dec 15, 2023

This isn't great, but you can copy/override AbstractCouchbaseConfiguration.customConversions(getCryptoManager(), getObjectMapper()) and add your converters to newConverters.

	public CustomConversions customConversions(CryptoManager cryptoManager, ObjectMapper objectMapper) {
		List<Object> newConverters = new ArrayList();
		// newConverters.add(....) // <-- add here
		newConverters.add(new OtherConverters.EnumToObject(getObjectMapper()));
		newConverters.add(new IntegerToEnumConverterFactory(getObjectMapper()));
		newConverters.add(new StringToEnumConverterFactory(getObjectMapper()));
		newConverters.add(new BooleanToEnumConverterFactory(getObjectMapper()));
		CustomConversions customConversions = CouchbaseCustomConversions.create(configurationAdapter -> {
			SimplePropertyValueConversions valueConversions = new SimplePropertyValueConversions();
			valueConversions.setConverterFactory(
					new CouchbasePropertyValueConverterFactory(cryptoManager, annotationToConverterMap(), objectMapper));
			valueConversions.setValueConverterRegistry(new PropertyValueConverterRegistrar().buildRegistry());
			valueConversions.afterPropertiesSet(); // wraps the CouchbasePropertyValueConverterFactory with CachingPVCFactory
			configurationAdapter.setPropertyValueConversions(valueConversions);
			configurationAdapter.registerConverters(newConverters);
		});
		return customConversions;
	}

Eventually I can replace the customConversions(CryptoManager, ObjectMapper) method with

public CustomConversions customConversions(CryptoManager cryptoManager, ObjectMapper objectMapper, List<Object> newConverters ) {

@mikereiche mikereiche added type: enhancement A general enhancement status: feedback-provided Feedback has been provided and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 15, 2023
@mikereiche mikereiche self-assigned this Dec 15, 2023
@bipoool
Copy link
Contributor

bipoool commented Dec 28, 2023

hey @mikereiche, Can I work on this? If you have not started working on this?

@bipoool
Copy link
Contributor

bipoool commented Jan 3, 2024

hey @mikereiche @roman-sinyakov, I've Raised a PR for this. Can you please check this?
#1886

@mikereiche
Copy link
Collaborator

Thanks very much. I'll look at it next week.

@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
status: feedback-provided Feedback has been provided type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants