Skip to content

Latest commit

 

History

History
106 lines (71 loc) · 3.88 KB

README.md

File metadata and controls

106 lines (71 loc) · 3.88 KB

Java Serializable 📚

Java License

🌐 Overview

Welcome to the java-serializable library! This Java library provides a simple way to easily serialize all the objects from java (including the ones without the Serializable interface implementation) with an extreme performance and customization

🚀 Features

  • No Dependency on Empty Constructors: Unlike other serializers like GSON, this library doesn't require an empty constructor for deserialization. This means you can freely use final fields in your classes.
  • Support for final Fields: Deserialization occurs without invoking any constructor, allowing you to maintain immutable classes with final fields.
  • No Need for Serializable: Serialize and deserialize classes without implementing the Serializable interface. Though not recommended, it offers flexibility when needed.
  • Clean Output: The serialized data (e.g., JSON) is free of class names or unnecessary information, making it perfect for use in REST APIs.
  • Array Serialization: Easily serialize arrays of objects, regardless of whether they implement the Serializable interface.
  • High Performance: The serialization process is optimized for speed and efficiency.
  • Highly Customizable: Gain full control over the serialization process with extensive customization options.

🛠️ Installation

For now, there's no public artifact at the Maven Central for this. To use the Java Serializable library. You should install it manually at your project using Maven Guide to installing 3rd party JARs

✨ Usage

Annotation

The library has an optional annotation called @KnownAs that you can add to a field.

Here's an example of how to use it:

import codes.laivy.serializable.annotations.KnownAs;

public final class User {

    @KnownAs(name = "user_name") // Optional annotation
    private final String name;
    
    private final int age;
    
    private final transient String data; // This data will be ignored, it's transient!

    // Constructors, getters, and setters
    
    public String toString() {
        return "User{name='" + name + "',age=" + age + "}";
    }
    
}

Serialization Example

Here's an example of how the serialization works with the @KnownAs annotation and without it:

import codes.laivy.serializable.Serializer;

public class Main {
    public static void main(String[] args) {
        User user = new User("Alice", 30);

        JsonElement json = Serializer.toJson(user);
        System.out.println(json);
        // Output: {"user_name":"Alice","age":30}
        
        user = Serializer.fromJson(User.class, json);
        System.out.println(user);
        // Output: User{name='Alice',age=30}
    }
}

📜 API Documentation

For detailed API documentation, please refer to the Javadoc.

🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a pull request

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.

Acknowledgements 🙏

  • Thanks to all the contributors who have helped improve this project.
  • Special thanks to the open-source community for their continuous support and contributions.

Feel free to reach out if you have any questions or need further assistance!

Happy coding! 🚀