question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conflicting setter definitions for property \“currency\”: javax.money.MonetaryAmountFactory

See original GitHub issue

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 ;

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

I have followed this reference (http://stairs-jumper.livejournal.com/33244.html) and wrote following code snippet[2]; and registered it at @ApplicationPath. But still getting same issue.

    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));
            }
        }
    }

Registering;

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

SO query

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mykolapolonskyicommented, Apr 24, 2017

Maybe will be useful even with this huge delay: If you’re using swagger-maven-plugin validate version. I’ve fount that in version 3.1.4 is very old version of FaxterXML(1.9.X branch) Fix for it already placed in the 3.1.5-SNAPSOT of this plugin

1reaction
cowtowncodercommented, May 26, 2016

First: have you tried latest Jackson version (2.7.4)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conflicting setter definitions for property \"currency\": javax ...
Conflicting setter definitions for property \"currency\": javax.money.MonetaryAmountFactory ... How can i overcome this issue? ... This is a swagger ...
Read more >
MonetaryAmountFactory (JSR 354 (Money and Currency API ...
Implementations of this interface allow to get MonetaryAmount instances providing different data as required: the CurrencyUnit , or the corresponding currency ...
Read more >
javax.money.Monetary java code examples - Tabnine
Static factory method for creating a new instance of {@link RoundedMoney} . * * @param currencyCode The target currency as ISO currency code....
Read more >
json - How to overcome &quot;Conflicting setter definitions for ...
... java.lang.illegalargumentexception: conflicting setter definitions property "currency": javax.money.monetaryamountfactory#setcurrency(1 ...
Read more >
moneta | RESTful web service interface to a relational database
Money ; import org.springframework.boot.context.properties.ConfigurationProperties ... Validate currency code matches one of the allowed values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found