How to overcome “Conflicting setter definitions for property ”?

隐身守侯 提交于 2019-12-11 13:32:48

问题


I use com.fasterxml.jackson and io.swagger libraries. In my REST endpoint I use org.javamoney.moneta.Money type for a GET query. When deploying the war i get following exception 1;

I have followed this reference and wrote following code[2]; and registered it at @ApplicationPath. But still getting same issue. Any guide would be really helpful?

@ApplicationPath("/rest")
public class RestApplication extends Application {
@Override
    public Set<Class<?>> getClasses() {
        HashSet<Class<?>> set = new HashSet<Class<?>>();
        set.add(com.test.JsonMoneyProvider.class);

[2]

import javax.money.CurrencyUnit;
    import javax.money.Monetary;
    import javax.money.MonetaryAmountFactory;
    import javax.ws.rs.ext.Provider;
    import javax.xml.bind.annotation.XmlTransient;

    import com.fasterxml.jackson.annotation.JsonIgnore;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;

    @Provider
    public class JsonMoneyProvider extends JacksonJsonProvider {
        public JsonMoneyProvider() {
            ObjectMapper mapper = new ObjectMapper();
            mapper.addMixIn(MonetaryAmountFactory.class, MixIn.class);
            setMapper(mapper);
        }

        public static interface MixIn {
            @JsonIgnore
            @XmlTransient
            MonetaryAmountFactory setCurrency(CurrencyUnit currency);

            @JsonIgnore
            @XmlTransient
            default MonetaryAmountFactory setCurrency(String currencyCode) {
                return setCurrency(Monetary.getCurrency(currencyCode));
            }
        }
    }

1

Caused by: java.lang.IllegalArgumentException: Conflicting setter definitions for property "currency": javax.money.MonetaryAmountFactory#setCurrency(1 params) vs javax.money.MonetaryAmountFactory#setCurrency(1 params)
        at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:293)
        at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:246)
        at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:127)
        at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:99)
        at io.swagger.jackson.ModelResolver.resolveProperty(ModelResolver.java:106)
        a

来源:https://stackoverflow.com/questions/37452689/how-to-overcome-conflicting-setter-definitions-for-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!