ORMLite and Images saved as BLOB on Android

我的未来我决定 提交于 2019-11-30 05:07:58

You can indeed store byte[] fields in ORMLite. To quote the manual about byte arrays:

Array of bytes (byte[]) persisted as SQL type VARBINARY. This is different from the DataType.SERIALIZABLE type which serializes an object as an array of bytes.

NOTE: Because of backwards compatibility, any fields that are of type byte[] must be specified as DataType.BYTE_ARRAY or DataType.SERIALIZABLE using the dataType field and will not be auto-detected.

So, to use byte[] you will need to specify the type of the data:

@DatabaseField(dataType = DataType.BYTE_ARRAY)
byte[] imageBytes;

The trick is that ORMLite does not automatically detect the type of the byte[] because of some backwards compatibility issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!