Parceler:无法找到ForeignCollection类型的读/写生成器

时间:2016-06-08 12:44:52

标签: java android ormlite parceler

我尝试使用Parceler来使用ORMLite,但是Parceler会收到错误:

Error:(44, 36) error: Parceler: Unable to find read/write generator for type com.j256.ormlite.dao.ForeignCollection<PassKeyItem> for CategoryItem.passKeyItems

这是我的对象:

CategoryItem.class

@Parcel
@DatabaseTable(tableName = "categories")
public class CategoryItem {
     ...
    @ForeignCollectionField(columnName = FIELD_PASS_KEY_ITEMS)
    ForeignCollection<PassKeyItem> passKeyItems;
}

PassKeyItem.class

@Parcel
@DatabaseTable(tableName = "passkey")
public class PassKeyItem {
...
  @DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = FIELD_CATEGORY_ITEM_ID)
    private CategoryItem categoryItem;
}

2 个答案:

答案 0 :(得分:6)

您需要提供转换器,因为Parceler不知道如何序列化Path_t pathInfo; while (!file.atEnd()) { QByteArray line = file.readLine().trimmed(); // remove white space at ends if (line.startsWith("sendLink")) { // do sendLink stuff... // maybe you need to assign a new pathInfo...? } else if (line.startsWith("PATH") { // now get the rest of the PATH line. This should keep reading // and appending lines until there is no '\' at the end. while (line.endsWith("\")) { // remove the "\" from the end line.chop(1); // Read the next line (trim white space) line.append(file.readLine().trimmed()); } // assuming you don't want the brackets? line.remove('('); line.remove(')'); // split the line QList<QByteArray> words = line.split(','); // populate your struct - assuming that the positions are always 0 and 10... // otherwise you will have to parse this bit too pathInfo.outputESResource = words[0].toLatin1(); // convert to QString for your struct pathInfo.inputESResource = words[10].toLatin1(); // convert to QString for your struct // do something with pathInfo.... } }

以下是文档中的示例:

ForeignCollection

https://github.com/johncarl81/parceler#custom-serialization

的更多信息

答案 1 :(得分:2)

也许您忘了将@Parcel放在班级名称之上。

*适用于此处有相同错误消息的任何人。