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

Conflicting setter definitions for property "target" #372

Open
milindsingh opened this issue Dec 6, 2022 · 1 comment
Open

Conflicting setter definitions for property "target" #372

milindsingh opened this issue Dec 6, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@milindsingh
Copy link

Describe the bug
Springdoc open api spec fails

To Reproduce
Setup spring app with springdoc

Expected behavior
no error

Screenshots/Code snippet

java.lang.IllegalArgumentException: Conflicting setter definitions for property "target": com.commercetools.api.models.review.Review#setTarget(com.commercetools.api.models.channel.ChannelReference) vs com.commercetools.api.models.review.Review#setTarget(java.lang.Object) vs com.commercetools.api.models.review.Review#setTarget(com.commercetools.api.models.product.ProductReference)
	at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._selectSetterFromMultiple(POJOPropertyBuilder.java:561) ~[jackson-databind-2.13.4.2.jar:2.13.4.2]
	at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:492) ~[jackson-databind-2.13.4.2.jar:2.13.4.2]

Stack information (please complete the following information):

  • Java: 17
  • SDK: latest

Additional context
remove void setTarget(Object var1) in com.commercetools.api.models.review.Review ?

@milindsingh milindsingh added the bug Something isn't working label Dec 6, 2022
@jenschude
Copy link
Contributor

jenschude commented Dec 7, 2022

This is an issue of the ObjectMapper used by springdoc.

The SDK adds the ApiModule to the ObjectMapper used for De-/Serialization. This includes a ReviewMixin class which helps correctly deserializing the review object.

You may have to investigate how to customize the modelconverters or objectmapper used by springdoc. One option could be to use the replaceWithSchema or replaceWithClass method as described here https://springdoc.org/#how-can-i-use-enable-springdoc-openapi-monetaryamount-support (use only of the config methods mentioned below)

    interface CustomReview {
       // ... add necessary properties and jackson annotations
    }

    static {
        SpringDocUtils.getConfig()
                .replaceWithClass(
                        com.commercetools.api.models.review.Review.class,
                        CustomReview.class
                )
            .replaceWithSchema(
                com.commercetools.api.models.review.Review.class,
                new ObjectSchema()
                    .addProperty(
                        "target",
                        new ComposedSchema()
                            .addOneOfItem(new ObjectSchema().$ref("CategoryReview"))
                            .addOneOfItem(new ObjectSchema().$ref("ProductReview"))
                    )
                    // ... add the other properties for review class
            );
    }

I also saw other code snippets which were more sophisticated but may be harder to adapt to your needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants