SiimKinks / sqlitemagic

Compile time processed, annotation driven, no reflection SQLite database layer for Android
https://siimkinks.github.io/sqlitemagic/javadoc/
Apache License 2.0
121 stars 11 forks source link

How to handle a list of string #8

Closed vincent-paing closed 6 years ago

vincent-paing commented 6 years ago

Currently, I have the following field in my entity

@Table(persistAll = true, value = "table_movie") @AutoValue public abstract class MovieEntity {

  @Id @Column(value = "movie_id") public abstract long id();

  @Column(value = "movie_name") public abstract String name();

  @Column(value = "category") public abstract CategoryEntity category();

  @Column(value = "alt_names") public abstract List<String> alternativeNames();
}

I have added a Transformer class for List String that convert into JSON vice versa.

@Transformer public class StringListTransformer {

  @ObjectToDbValue public static String objectToDBValue(List<String> object) {
    return new Gson().toJson(object);
  }

  @DbValueToObject public static List<String> dbValueToObject(String dbValue) {
    return new Gson().fromJson(dbValue, new TypeToken<List<String>>() {
    }.getType());
  }
}

When I compile my project it gave out this error with no instructions to recover

Error:Execution failed for task ':sqlitemagic:compileDebugJavaWithJavac'. java.lang.ClassCastException: com.sun.tools.javac.code.Type$ClassType cannot be cast to javax.lang.model.type.ArrayType

EDIT: Seems like it's because of The Transformer class, when I remove it and the list field, it compile successfully.

SiimKinks commented 6 years ago

This is a bug in transformer method types parsing. You can replace List with String[] until this issue is fixed.

vincent-paing commented 6 years ago

AutoValue only support primitive arrays so using String[] with AutoValue will not work. For now, I will just use without AutoValue

SiimKinks commented 6 years ago

This bug is fixed in version 0.17.0