Class Deserializers


  • public class Deserializers
    extends java.lang.Object
    A utility class for managing and retrieving Deserializer instances based on the deserialized type.

    This class allows registration and lookup of deserializers via SPI (Service Provider Interface), supporting priority-based resolution to determine the most or least specific deserializer available.

    Example Usage

    
     // Create an instance with the default class loader
     Deserializers deserializers = new Deserializers();
    
     // Load deserializers via SPI
     deserializers.loadSPI();
    
     // Retrieve the highest priority deserializer for a specific type
     Deserializer<MyType> deserializer = deserializers.getHighestPriority(MyType.class);
    
     // Deserialize an object using the retrieved deserializer
     MyType obj = deserializer.deserialize(data);
     
    Since:
    1.0.0
    Author:
    Mercy
    • Constructor Detail

      • Deserializers

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

        public Deserializers()
    • Method Detail

      • loadSPI

        public void loadSPI()
      • getMostCompatible

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

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

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

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