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. πΎβ¨
- Simplified persistence π: Provides easy-to-use methods (
saveandload) for serializing and deserializing objects. - Generic type compatibility π: Uses a generic approach that works with any data type implementing the
Serializableinterface. - Class validation β : Includes internal mechanisms to verify compatibility between stored data and expected classes during deserialization.
- Unique identification π: Provides a method to retrieve the
serialVersionUIDof 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.
// 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");wrapper.setContent(myObject); // Set the object to be saved
wrapper.save(); // Serialize and save to the filewrapper.load(); // Deserialize and load from the file
MyClass loadedObject = wrapper.getContent(); // Get the loaded objectlong serialID = wrapper.getContentSerialID();
System.out.println("SerialVersionUID: " + serialID);- πΎ
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 theserialVersionUIDof the object's class.
- Java 8 β or higher (compatible with the standard serialization API).
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. π
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! πͺβ¨