ORMLite and Images saved as BLOB on Android

后端 未结 1 800
逝去的感伤
逝去的感伤 2020-12-29 07:47

So I recently switched my database stuff over to ORMLite in my android tablet application I am writing. So far so good, got most things refactored/recoded. Though I am hav

相关标签:
1条回答
  • 2020-12-29 08:22

    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.

    0 讨论(0)
提交回复
热议问题