ngageoint / elasticgeo

ElasticGeo provides a GeoTools data store that allows geospatial features from an Elasticsearch index to be published via OGC services using GeoServer.
GNU General Public License v3.0
169 stars 85 forks source link

Conflicting getter definitions for property "hits" #70

Closed dclemenzi closed 6 years ago

dclemenzi commented 6 years ago

We are using a newer version of com.fasterxml.jackson (2.9.1) which when running inside of a unit test is overriding the version used by gt-elasticsearch causing this issue:

Caused by: java.lang.IllegalArgumentException: Conflicting getter definitions for property "hits": mil.nga.giat.data.elasticsearch.ElasticResponse#getHits(0 params) vs mil.nga.giat.data.elasticsearch.ElasticResponse#getResults(0 params)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getGetter(POJOPropertyBuilder.java:432)
    at com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition.getAccessor(BeanPropertyDefinition.java:188)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._getSetterInfo(POJOPropertyBuilder.java:251)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getMetadata(POJOPropertyBuilder.java:231)
    at com.fasterxml.jackson.databind.deser.SettableBeanProperty.<init>(SettableBeanProperty.java:136)

This is a result of the following in ElasticResponse:

...
    @JsonProperty("hits")
    private ElasticResults results;

...

   public List<ElasticHit> getHits() {
        final List<ElasticHit> hits;
        if (results != null) {
            hits = results.getHits();
        } else {
            hits = new ArrayList<>();
        }
        return hits;
    }
...

which conflicts with each other. Apparently earlier version don't mind... but to resolve this we added an JsonIgnore annotation above the offending getter.

   @JsonIgnore
   public List<ElasticHit> getHits() {
        final List<ElasticHit> hits;
        if (results != null) {
            hits = results.getHits();
        } else {
            hits = new ArrayList<>();
        }
        return hits;
    }
sjudeng commented 6 years ago

Fixed in #71