Serializable Objects

You can store an instance of a Serializable class as a Blob value. To tell Slim3 Datastore to serialize the value, the field uses the annotation @Attribute(lob = true). Blob values are not indexed and cannot be used in query filters or sort orders.

Here is an example of a simple Serializable class that represents a file, including the file contents, a filename and a MIME type.

import java.io.Serializable;

public class DownloadableFile implements Serializable {
private static final long serialVersionUID = 1L;
   
private byte[] content;
   
private String filename;
   
private String mimeType;

   
// ... accessors ...
}

To store an instance of a Serializable class as a Blob value in a property, declare a field whose type is the class, and use the @Attribute(lob = true) annotation:

import DownloadableFile;
import org.slim3.datastore.Attribute;
// ...
   
@Attribute(lob = true)
   
private DownloadableFile file;

Next...

Continue to Array of bytes.

Comments