有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

ORMLite不知道如何存储java接口。util。列表

产品

@DatabaseTable
public class Product implements Serializable {
private static final long serialVersionUID = 1L;

public Product() {
    // TODO Auto-generated constructor stub
}

public Product(String originalId) {
    this.originalId = originalId;
}

@DatabaseField(id = true)
private String originalId;

...

@DatabaseField
private List<SkuInfo> skusInfo;

SkuInfo

public class SkuInfo implements Serializable {

private static final long serialVersionUID = 1L;
...
}

错误是:

java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.

当我使用:

@DatabaseField(dataType = DataType.SERIALIZABLE)
private List<SkuInfo> skusInfo;

错误更改为:

java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.

我已经在另一篇帖子中读到了关于标签Foreign的内容,但我的物品不是外键


共 (2) 个答案

  1. # 1 楼答案

    java.lang.IllegalArgumentException: ORMLite does not know how to store interface java.util.List for field skusInfo. Use another class or a custom persister.

    就为了子孙后代,你可以把它改成一个ArrayList,它实际上实现了java.io.Serializable,因为这就是它想要的。不幸的是,List没有这样做,ORMLite抛出了异常

  2. # 2 楼答案

    我使用了一个自定义的可序列化对象,比如posthere,并进行了工作

    public class SerializableCollectionsType extends SerializableType {
        private static SerializableCollectionsType singleton;
        public SerializableCollectionsType() {
            super(SqlType.SERIALIZABLE, new Class<?>[0]);
        }
    
        public static SerializableCollectionsType getSingleton() {
            if (singleton == null) {
                singleton = new SerializableCollectionsType();
            }
            return singleton;
        }
        @Override
        public boolean isValidForField(Field field) {
            return Collection.class.isAssignableFrom(field.getType());
        }
    }
    

    产品

    @DatabaseField(persisterClass = SerializableCollectionsType.class)
    private List<SkuInfo> skusInfo;