Class Serializers


  • public class Serializers
    extends java.lang.Object
    A utility class for managing and retrieving Serializer instances.

    This class provides methods to load serializers via SPI (Service Provider Interface), retrieve the most compatible serializer for a given type, and get serializers based on priority.

    Example Usage

    
     Serializers serializers = new Serializers();
     serializers.loadSPI(); // Load all available serializers from SPI
    
     // Get the highest priority serializer for String
     Serializer<String> highestPrioritySerializer = serializers.getHighestPriority(String.class);
    
     // Get the lowest priority serializer for String
     Serializer<String> lowestPrioritySerializer = serializers.getLowestPriority(String.class);
    
     // Get the most compatible serializer for String
     Serializer<?> compatibleSerializer = serializers.getMostCompatible(String.class);
     
    Since:
    1.0.0
    Author:
    Mercy
    • Constructor Summary

      Constructors 
      Constructor Description
      Serializers()  
      Serializers​(java.lang.ClassLoader classLoader)  
    • Constructor Detail

      • Serializers

        public Serializers​(java.lang.ClassLoader classLoader)
      • Serializers

        public Serializers()
    • Method Detail

      • loadSPI

        public void loadSPI()
      • getMostCompatible

        public Serializer<?> getMostCompatible​(java.lang.Class<?> serializedType)
        Get the most compatible instance of Serializer by the specified deserialized type
        Parameters:
        serializedType - the type to be serialized
        Returns:
        null if not found
      • getHighestPriority

        public <S> Serializer<S> getHighestPriority​(java.lang.Class<S> serializedType)
        Get the highest priority instance of Serializer by the specified serialized type
        Type Parameters:
        S - the type to be serialized
        Parameters:
        serializedType - the type to be serialized
        Returns:
        null if not found
      • getLowestPriority

        public <S> Serializer<S> getLowestPriority​(java.lang.Class<S> serializedType)
        Get the lowest priority instance of Serializer by the specified serialized type
        Type Parameters:
        S - the type to be serialized
        Parameters:
        serializedType - the type to be serialized
        Returns:
        null if not found
      • get

        @Nonnull
        public <S> java.util.List<Serializer<S>> get​(java.lang.Class<S> serializedType)
        Get all instances of Serializer by the specified serialized type
        Type Parameters:
        S - the type to be serialized
        Parameters:
        serializedType - the type to be serialized
        Returns:
        non-null List