Serialisation Service
This module is part of the Open4Goods project and provides functionality for serializing and deserializing objects to/from JSON and YAML formats. It also offers methods for Base64 encoding/decoding of strings.
Features
-
JSON and YAML Serialization:
Serialize objects to JSON or YAML with support for pretty printing. -
Deserialization:
Deserialize JSON or YAML strings back into Java objects. -
Deep Cloning:
Create deep clones of objects using JSON serialization. -
Binary Serialization:
Serialize objects to a binary JSON representation. -
Base64 Compression/Decompression:
Encode strings to Base64 and decode them back.
How to Use
-
Include the Dependency
Ensure that your Maven project includes theserialisationmodule as a dependency. -
Inject the Service
Use constructor injection in your Spring components:@Service public class MyService { private final SerialisationService serialisationService; public MyService(SerialisationService serialisationService) { this.serialisationService = serialisationService; } public void process() { // Example usage: MyObject obj = new MyObject(...); try { String json = serialisationService.toJson(obj, true); // Process JSON... } catch (SerialisationException e) { // Handle exception } } } -
Running Tests
A comprehensive test suite is available. To run tests, use:mvn testThe module uses an
application-test.ymlfor test-specific configurations.
Building the Project
Ensure you have Java 11+ installed and then run:
mvn clean install
Additional Information
For more details, refer to the Javadoc comments in the source code and the unit tests in the src/test directory.
Happy coding!