Storing Custom Objects
Up to this point, you have only stored byte arrays or strings in a record store. As explained in the diary example, Strings have a method with which you can convert them to byte arrays, and a constructor that takes a byte array as input. But if you want to store your own objects, you need to provide a way to convert them to byte arrays and back yourselves.
The simplest solution would be to add the same constructor and getBytes() method to your custom objects that String already provides. You can implement the mapping two different ways. One possibility is to convert the byte array to different fields in your object. The other possibility is to keep the byte array as storage, and to implement field access methods as wrappers ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access