Skip to content

PersistenceUtils is a lightweight Java module designed to simplify data persistence by providing an intuitive and reusable wrapper for serializing and deserializing Serializable objects. πŸ“¦βœ¨

Notifications You must be signed in to change notification settings

blacknoize404/PersistenceUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PersistenceUtils πŸ“¦

PersistenceUtils is a persistence module designed to simplify the serialization and deserialization of data in Java. This module provides a generic wrapper that allows you to save and load persistent objects easily, ensuring that data is stored and retrieved correctly from files. πŸ’Ύβœ¨

Key Features 🌟

  • Simplified persistence πŸ“‚: Provides easy-to-use methods (save and load) for serializing and deserializing objects.
  • Generic type compatibility πŸ”„: Uses a generic approach that works with any data type implementing the Serializable interface.
  • Class validation βœ…: Includes internal mechanisms to verify compatibility between stored data and expected classes during deserialization.
  • Unique identification πŸ”‘: Provides a method to retrieve the serialVersionUID of the managed class, helping to ensure data integrity when working with different versions of a class.
  • Modular and reusable design 🧩: The module's design is clean and optimized for use in projects where data persistence is required.

Basic Usage πŸ› οΈ

Creating an Instance πŸ†•

// Create a wrapper to persist an object of type MyClass
PersistentWrapper<MyClass> wrapper = PersistentWrapper.of(MyClass.class, "path/to/file.dat");

// Optionally, you can initialize it with an existing object
MyClass myObject = new MyClass();
PersistentWrapper<MyClass> wrapperWithData = PersistentWrapper.of(myObject, MyClass.class, "path/to/file.dat");

Saving Data πŸ’Ύ

wrapper.setContent(myObject); // Set the object to be saved
wrapper.save(); // Serialize and save to the file

Loading Data πŸ“‚

wrapper.load(); // Deserialize and load from the file
MyClass loadedObject = wrapper.getContent(); // Get the loaded object

Getting the serialVersionUID πŸ”‘

long serialID = wrapper.getContentSerialID();
System.out.println("SerialVersionUID: " + serialID);

Main Methods πŸ“‹

  • πŸ’Ύ save(): Saves the current object to the specified file.
  • πŸ“‚ load(): Loads the object from the specified file.
  • 🎁 getContent(): Retrieves the wrapped object.
  • ✍️ setContent(E content): Sets a new object in the wrapper.
  • πŸ”‘ getContentSerialID(): Returns the serialVersionUID of the object's class.

Requirements βš™οΈ

  • Java 8 β˜• or higher (compatible with the standard serialization API).

Contributions 🀝

Contributions are welcome! If you find any issues, have suggestions for improvements, or want to add new features, feel free to open an issue or submit a pull request. πŸš€

License πŸ“„

This project is licensed under the MIT License. πŸ“œ


Author: BarnΓ©s Inside πŸ‘¨β€πŸ’»
Version: 0.6 πŸ†•

If you need a robust and flexible solution for handling data persistence in your Java projects, PersistenceUtils is the ideal tool! πŸ’ͺ✨

About

PersistenceUtils is a lightweight Java module designed to simplify data persistence by providing an intuitive and reusable wrapper for serializing and deserializing Serializable objects. πŸ“¦βœ¨

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages