org.ektorp.InvalidDocumentException: Cannot resolve id accessor in class

291 Views Asked by At

I'm coding a java application to insert data on CouchDB. For that I'm using Ektorp and I'm getting the exception org.ektorp.InvalidDocumentException: Cannot resolve id accessor in class

These are my maven dependencies:

<dependency>
  <groupId>org.ektorp</groupId>
  <artifactId>org.ektorp</artifactId>
  <version>1.4.4</version>
</dependency>

<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
  <version>2.9.10</version>
</dependency>

The POJO, as described here

public class Item {

    @JsonProperty("_index")
    public String index;

    @JsonProperty("_type")
    public String type;

    @JsonProperty("_id")
    public String id;

    @JsonProperty("_score")
    public float score;

}

The repository:

public class ItemRepository extends CouchDbRepositorySupport<Item> {
    public ItemRepository(CouchDbConnector db) {
        super(Item.class, db);
    }
}

And how I'm trying to add:

Item x = new Item();
x.id = "1291";
x.index="test_index";
x.score = 1;
x.type = "_doc";

this.repo = new ItemRepository(this.db);
this.repo.add(x);

The error description:

Exception in thread "main" org.ektorp.InvalidDocumentException: Cannot resolve id accessor in class org.example.Item
    at org.ektorp.util.Documents$MethodAccessor.assertMethodFound(Documents.java:165)
    at org.ektorp.util.Documents$MethodAccessor.<init>(Documents.java:136)
    at org.ektorp.util.Documents.getAccessor(Documents.java:113)
    at org.ektorp.util.Documents.getRevision(Documents.java:77)
    at org.ektorp.util.Documents.isNew(Documents.java:85)
    at org.ektorp.support.CouchDbRepositorySupport.add(CouchDbRepositorySupport.java:100)
    at org.example.DataBase.addItem(DataBase.java:69)
    at org.example.App.main(App.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

I'm not sure what I'm doing wrong. I think it is the Jackson JSON library that I'm not sure If I'm using the right one since the link they have in the doc does not exist anymore.

I appreciate any help

1

There are 1 best solutions below

0
André Luiz On

I solved the problem. It was just a matter of placing the right dependency. This id the right one:

  <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-core-lgpl</artifactId>
      <version>1.9.13</version>
  </dependency>