如何让ObjectBox支持Map?
How to make ObjectBox support Map?
@Entity
public class AgendaEntity {
@Id public long id;
private Map unitMap;
public Map getUnitMap() {
return unitMap;
}
public void setUnitMap(Map unitMap) {
this.unitMap = unitMap;
}
}
导致以下错误:-
error: [ObjectBox] Field type "java.util.Map" is not supported. Consider making the target an @Entity, or using @Convert or @Transient on the field (see docs).
如果您无法避免地图(例如,您有固定数量的条目吗?),请为您的地图编写一个转换器,详情请参阅custom types docs。
示例:
@Convert(converter = MyUnitConverter.class, dbType = String.class)
private Map unitMap;
MyUnitConverter 必须由您实现。
@Entity
public class AgendaEntity {
@Id public long id;
private Map unitMap;
public Map getUnitMap() {
return unitMap;
}
public void setUnitMap(Map unitMap) {
this.unitMap = unitMap;
}
}
导致以下错误:-
error: [ObjectBox] Field type "java.util.Map" is not supported. Consider making the target an @Entity, or using @Convert or @Transient on the field (see docs).
如果您无法避免地图(例如,您有固定数量的条目吗?),请为您的地图编写一个转换器,详情请参阅custom types docs。
示例:
@Convert(converter = MyUnitConverter.class, dbType = String.class)
private Map unitMap;
MyUnitConverter 必须由您实现。