Module id.xfunction
Package id.xfunction

Class ObjectStore<T extends Serializable>

Object
ObjectStore<T>

public class ObjectStore<T extends Serializable> extends Object
Persistent store for Serializable object. Object is stored in a file you specify. Later you can restore it back. Useful in case you need some simple persistent and don't have time to deal with DB (JPA), or adding dependency to some Json library etc. The drawback of this store is that you would not be able manually to modify the object values in the file after it is stored.

If you want to store Collection object make sure to parameterize it with collection implementation which implements Serializable and not with Collection interface. For example you cannot store Set but you can store HashSet since Set does not implement Serializable and HashSet does.

  • Constructor Details

    • ObjectStore

      public ObjectStore(Path file)
      Create a store and use following file
  • Method Details

    • save

      public void save(T obj)
      Persist given object into current store
    • load

      public Optional<T> load()
      Loads object from a current store