jsondb-core icon indicating copy to clipboard operation
jsondb-core copied to clipboard

No class found with @Document Annotation and attribute collectionName as: User, Android

Open DzDev202020 opened this issue 3 years ago • 2 comments

Hello there, when I try to create collection this exception is thrown " No class found with @Document Annotation and attribute collection Name as: User ", I am sure 100% my code and implementation are correct. If I use it in java code test it work 100%. The problem in reflection does not find the classes at runtime (samsung device). check the code below please:

this is my db init code:

String baseScanPackage = "com.myapp.chat.model";
  String base64EncodedKey = CryptoUtil.generate128BitKey(SomeSecretPassword, SomeUniqueSecreteSalt);
  ICipher cipher = new Default1Cipher(base64EncodedKey);
        jsonDBTemplate = new JsonDBTemplate(dbFilesLocation, baseScanPackage, cipher);

 if (!jsonDBTemplate.collectionExists(User.class))
            jsonDBTemplate.createCollection(User.class);

this is my User class code:

@Document(collection = "User", schemaVersion= "1.0")
public class User implements Serializable {

    @Id
    public String id;
   

    public User() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
   }

the problem is in reflection does not find classes at runtime.

DzDev202020 avatar Apr 04 '22 17:04 DzDev202020

As you noticed in #42 there is currently No way to use this library on Android as the reflection lib is Not working. Currently the best way to Go is to use a working library targeting Android Like Realm, Objectbox, Room, etc

Hatzen avatar Apr 05 '22 05:04 Hatzen

@Hatzen I appreciate your reply, big thanks for you. How other libraries work ?? which are using annotation, like Room for example your use @Entity , @Id .... , how did they used reflection or finding classes, Probably it is prebuild process or some thing like that is related to gradle?. actually I am low experience with gradle.

DzDev202020 avatar Apr 05 '22 08:04 DzDev202020